I recently upgraded an older Angular.js application from Typescript 2.7 to 3.5 and successfully compiled it using tsc.exe
.
During application runtime, I encountered an error message in certain parts of the code:
TypeError: Cannot read property 'EnumLiteral1' of undefined
For example, in Typescript, I have an Enum (not using const
in the declaration) defined as follows:
namespace App.Contracts {
export enum MyEnum {
EnumLiteral1,
EnumLiteral2,
...
}
}
In Typescript 2.7, I used to import and use this Enum like this:
import MyEnum = App.Contracts.MyEnum;
The usage was simply MyEnum.EnumLiteral1
.
However, with Typescript 3.5, I encountered an issue where MyEnum
is accessed as if it were an undefined class instance. It seems that in 3.5, the Enum code is generated after the code that uses the Enum, unlike in 2.7 where the Enum code is generated before.
I attempted to access the Enum by specifying the fully qualified namespace, which worked as a temporary solution. Before fully committing to this approach, I would like to understand if there is a specific change I need to make for it to work correctly.
I hope my explanation is clear. Please let me know if further clarification is needed.
My question: Is this a bug, or is there a specific adjustment I should make to resolve this issue?