Imported const enum is not inlined in generated code
See original GitHub issueTypeScript Version: 2.4.0
Code
// a.ts
export const enum Foo {
Bar = 'bar'
}
// b.ts
import { Foo } from './a'
Foo.Bar // TypeError or ReferenceError, depending on how it's compiled
Expected behavior:
Foo.Bar
to be replaced with 'bar'
Actual behavior:
The import is deleted and Foo.Bar
is left as is
Issue Analytics
- State:
- Created 6 years ago
- Reactions:34
- Comments:24 (9 by maintainers)
Top Results From Across the Web
typescript - Enum type not defined at runtime - Stack Overflow
I now get 'const' enums can only be used in property or index access expressions or the right hand side of an import...
Read more >Enum classes | Kotlin Documentation
Each enum constant is an object. Enum constants are separated by commas. Since each enum is an instance of the enum class, it...
Read more >TypeScript enum versus const enum - Susan Potter
Today I found that there is a difference between enum and const enum in TypeScript in the generated JavaScript. Namely: with a non-const...
Read more >Google TypeScript Style Guide
Source Organization: Modules: Exports: Imports: Organize By Feature ... CONSTANT_CASE, global constant values, including enum values. See Constants below.
Read more >TSConfig Reference - Docs on every TSConfig option
A module file is a file that has imports and/or exports. ... Do not erase const enum declarations in generated code. const enum...
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
transpileOnly
means transpile every file one at a time… when the compiler is looking at one file, it has no way to know if the reference it is looking at is a const enum or not, since the declaration is in another file that it does not have access to…so I do not think you can mix these two concepts,
const enums
(require whole program information), andtranspileOnly
(one file at a time).I’ve also encountered this problem when
transpileOnly: true
. WithouttranspileOnly
, I can’t use multi-threading to speed up my webpack build (ts-loader, happypack, fork-ts-checker-webpack-plugin). Unfortunately, I’m dealing with +100,000 lines of legacy code, so removing all const enums is not feasible.Typescript version: 2.6.1