Constant enums are not compiled
See original GitHub issueHi guys. Imagine I have tsconfig.json
like
{
"compilerOptions": {"...whatever"},
"includes": [
"src/**/*"
]
}
and i have constant enum in src/data.d.ts
declare const enum Foo {
Bar = 1,
}
then simply src/index.ts
export const Bar = Foo.Bar;
tsc
’s output for index.ts
is exports.Bar = 1 /* Bar */;
but in indexSpec.tsx
import { Bar } from "./";
describe("Bar", () => {
it("is defined", () => {
expect(Bar).toBeDefined();
});
});
I’ve got ReferenceError: Foo is not defined
. Is it possible to make this work?
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Why are enum fields not considered constant at compile time?
They are not compile-time constants, as enums are runtime objects which are instantiated and capable of being mutated.
Read more >Handbook - Enums - TypeScript
Const enums can only use constant enum expressions and unlike regular enums they are completely removed during compilation. Const enum members are inlined...
Read more >TypeScript string enums, and when and how to use them
For constant enums, the enum must be the first member and it has no initializer. Also, their values can be computed or calculated...
Read more >Enum Types - Java™ Tutorials
An enum type is a special data type that enables for a variable to be a set of predefined constants. The variable must...
Read more >Defining compile time constant Enums : r/rust - Reddit
This gives the error "the size for values of type `[TestEnum]` cannot be known at compilation time the trait `Sized` is not implemented...
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
@rikkit I’m a bit hesitant because this doesn’t seem to be a ts-jest issue. On the other hand, I see the point in adding a note if there are a lot of people running into this issue.
Any PRs which update the README accordingly are welcome
@r00ger can this get added to the readme? It’s non obvious behaviour and it seems a lot of people spend time searching for the cause.