Enum type not defined at runtime

There's another way you can do this. If you don't want to export your enum you can define it as a const enum

const enum MyEnum {
   One = "one";
   Two = "two";
}

These are inlined by the compiler and are completely removed during compilation.


In my case of undefined enum, it turned out it's because of circular import:

export enum A {...} defined in file a.ts, export const b = ... defined in file b.ts;

import {A} from './a.ts' in b.ts, while import {b} from './b.ts' in a.ts.

The error was gone after removing circular imports.


I had the same problem when imported re-exported enum. It caused runtime error.

layout.ts

export enum Part { Column, Row }

index.ts

export * from './layout'

component.ts

import { Part  } from '../entities' // This causes error
import { Part } from '../entities/layout' // This works