Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constant enums are not compiled #112

Closed
pablobirukov opened this issue Feb 6, 2017 · 9 comments
Closed

Constant enums are not compiled #112

pablobirukov opened this issue Feb 6, 2017 · 9 comments

Comments

@pablobirukov
Copy link

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?

@kulshekhar
Copy link
Owner

Would it be possible for you to create a small repo that can reproduce this issue?

pablobirukov added a commit to pablobirukov/ts-jest-const-enum-sample that referenced this issue Feb 6, 2017
@pablobirukov
Copy link
Author

Please check tsc and npm t in the repo above @kulshekhar

@kulshekhar
Copy link
Owner

I just browsed through the linked repo. Isn't this more of a Typescript issue than something that's ts-jest specific?

@pablobirukov
Copy link
Author

Can be. I'll take a closer look during this week. Let's keep it open

@pablobirukov
Copy link
Author

@kulshekhar you right, this is default behaviour. So It shouldn't substitute constant enums even it it's <reference />d or defined in the same file

@jayphelps
Copy link

It's not clear whether there was a workaround for this or just SOL?

I'm consuming a third party library that exports constant enums, same result TypeError: Cannot read property 'X' of undefined because they are not inlined and no runtime code for them exists.

@kulshekhar
Copy link
Owner

@jayphelps in the linked repo, if the enum is exported and imported, it works fine. Is that possible in your case? A tiny repo with your issue would be the best way to see if we can get this working

@rikkit
Copy link
Contributor

rikkit commented 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.

@kulshekhar
Copy link
Owner

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants