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.

Constant enums are not compiled

See original GitHub issue

Hi 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:closed
  • Created 7 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
kulshekharcommented, Aug 30, 2017

@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

2reactions
rikkitcommented, Aug 30, 2017

@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.

Read more comments on GitHub >

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

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