question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issues with exporting and importing enums

See original GitHub issue

TypeScript 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:closed
  • Created 6 years ago
  • Reactions:49
  • Comments:38 (6 by maintainers)

github_iconTop GitHub Comments

57reactions
dskopa-softdevcommented, Oct 30, 2019

Why is it closed? I can’t use exported enum in my tests

actions.ts:

export const enum DefinitionActionType {
    LOADING_DEFINITIONS = 'definitions/LOADING_DEFINITIONS',
    LOADED_DEFINITIONS = 'definitions/LOADED_DEFINITIONS',
}

When running normally it’s fine, but when i run tests it fails:

 FAIL  src/reducers/definitions/reducer.test.ts
  ● Test suite failed to run

    TypeError: Cannot read property 'LOADING_DEFINITIONS' of undefined

      25 | export function reducer(state = initialState, action: DefinitionActions): State {
      26 |     switch (action.type) {
    > 27 |         case DefinitionActionType.LOADING_DEFINITIONS:
         |                                       ^
      28 |             return {
37reactions
thefillcommented, Jun 25, 2019

I can confirm this is still an issue for version “24.0.2”.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found