6
votes

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

1

1 Answers

10
votes

You need to tell the compiler it has been declared:

declare var selfGlobal: any;