-
Notifications
You must be signed in to change notification settings - Fork 45
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
TypeScript - ReferenceError: Can't find variable when using a declared enum #160
Comments
I may be missing something but TypeScript declarations are not generated into JavaScript, so the JavaScript for your example looks like this and MyModule is not there, so the same error would happen. Is it working for you without wallaby? If so, would it be possible to create a working sample, perhaps a sample Github repository so I could have a look? |
There seems to be a difference between the online compiler (and the npm typescript version 1.5.0-beta compiler) and my tsc.exe compiler (version 1.0.3.0). See this simple code: declare module MyModule{
export enum MyEnum{
First = 1,
Second= 2,
Third = 3,
}
}
function test() {
return MyModule.MyEnum.First;
} The online compiler (and npm typescript compiler) transpiles it to: function test() {
return MyModule.MyEnum.First;
} But when I run it with tsc, I get this js file generated: function test() {
return 1 /* First */;
} What workaround can I use, provided that I can't really change my d.ts file? |
I'll have a look why it happens, in a meantime, as a workaround, you may use bootstrap function where you may define the enum like: bootstrap: function (wallaby) {
MyModule = MyModule || {};
MyModule.MyEnum = MyModule.MyEnum || {};
MyModule.MyEnum.First = 1;
MyModule.MyEnum.Second = 2;
// etc
} |
It is indeed the difference between typescript compilers. v1.4 replaces |
Created the issue in TypeScript repo. |
Thanks. |
So as it looks like |
Take a look at the following TypeScript code:
Wallaby show an error on this code which says:
ReferenceError: Can't find variable: MyModule
This seems to be a problem with the
declare module
statement, as replacing it withmodule
(with nodeclare
) makes the problem go away, but this is the way the enum is declared in the d.ts file we are using.The text was updated successfully, but these errors were encountered: