typescript
enum_error
ai_generated
true
TS2748: Cannot access ambient const enums when 'isolatedModules' is enabled
ID: typescript/ts-enum-const-assertion
88%Fix Rate
90%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 5 | active | — | — | — |
Root Cause
Const enums are erased at compile time and cannot work with isolatedModules (required by bundlers like Vite, esbuild).
genericWorkarounds
-
90% success Use regular enums instead of const enums
// Instead of: const enum Direction { Up, Down } // Use: enum Direction { Up, Down }Sources: https://www.typescriptlang.org/docs/handbook/enums.html
-
88% success Use 'as const' objects instead of enums
const Direction = { Up: 'UP', Down: 'DOWN', } as const; type Direction = typeof Direction[keyof typeof Direction];Sources: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types
Dead Ends
Common approaches that don't work:
-
Disable isolatedModules to fix the error
80% fail
Bundlers like esbuild and Vite require isolatedModules; disabling breaks the build tool
Error Chain
Preceded by:
Frequently confused with: