Reference to global variable from a module
javascript, typescript
Solution
You need to tell the compiler it has been declared:
declare var selfGlobal: any;
Problem
I have a global variable declared in the html header and want to reference it from a class inside a module. How can I prevent compiler error: error TS2095: Could not find symbol 'selfGlobal'. ``` <html> <head> <script> var selfGlobal = this; var globalVariable = 1; </script> </head> <body> <script src="test.js"></script> </body> </html> ``` In test.ts ``` module Test{ export class TestClass { private _privateVariable:any; constructor() { this._privateVariable = selfGlobal.globalVariable; // compile error throws here, but the code can run } } } ``` Thanks! Mars