Issues with exporting and importing enums
See original GitHub issueTypeScript Version: 2.4.1
Code
file1.ts
export enum Colors {
Red = "RED",
Green = "GREEN",
Blue = "BLUE"
}
export enum Numbers {
ONE = 1,
TWO = 2
}
file2.ts
import { Colors, Numbers } from "./file1";
Expected behavior: Colors and Numbers should not be undefined in file2. Colors should be:
{
Red: "RED",
Green: "GREEN",
Blue: "BLUE"
}
Numbers should be
{
ONE: 1,
TWO: 2
1: "ONE"
2: "TWO"
}
Actual behavior: Colors and Numbers are undefined. Any enum entry requested fail with “Cannot read property ‘enum entry’ of undefined”. It seems that this only occurs in case of a circular dependency. If you remove the circular dependency everything seems to work fine.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:49
- Comments:38 (6 by maintainers)
Top Results From Across the Web
typescript - How to import an Enum - Stack Overflow
I'm using global TS importing and TS can't see the exported enum that I have put in a different file for this very...
Read more >TypeScript: Don't Export const enums - ncjamieson
If you are writing a library and you export a const enum , some developers will not be able to compile their applications...
Read more >Import an Enum from Another file using TypeScript | bobbyhadz
In order to be able to import an enum from a different file, it has to be exported using a named or default...
Read more >Using enums | Flow
Learn how to use Flow Enums, including their methods and exhaustive checking. ... enums to other values; Enums in a union; Exporting enums;...
Read more >Handbook - Enums - TypeScript
How TypeScript enums work. ... In all other cases enum member is considered computed. ... The unresolvable imports cause errors at runtime.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Why is it closed? I can’t use exported enum in my tests
actions.ts:
When running normally it’s fine, but when i run tests it fails:
I can confirm this is still an issue for version “24.0.2”.