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.

Imported const enum is not inlined in generated code

See original GitHub issue

TypeScript 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:open
  • Created 6 years ago
  • Reactions:34
  • Comments:24 (9 by maintainers)

github_iconTop GitHub Comments

7reactions
mhegazycommented, Nov 15, 2017

I’ve also encountered this problem when transpileOnly: true. Without transpileOnly, 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.

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), and transpileOnly (one file at a time).

7reactions
elijah-schowcommented, Nov 14, 2017

I’ve also encountered this problem when transpileOnly: true. Without transpileOnly, 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

Read more comments on GitHub >

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

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