Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I use a runtime variable, that is not known by typescript?

I need to use one global variable in typescript, that is defined at runtime.

I need this to transfer some config properties from server side language to javascript. I’m using typescript to generate my javascript files.

<script>
var globalProperties = {foo: 'bar', phpName: 'phpValue'};
</script>
<script src="/compiledTypeScriptFile.js"></script>

How can i use my globalProperties in compiledTypeScriptFile.ts? The globalProperties are automatically generated. So I cannot put them in a seperate ts file or something like this.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Im not using any client side lib except for jQuery.

Please consider globalProperties as type any[]. The name value pairs will extend automatically in the future.

>Solution :

Just declare it:

declare var globalProperties: { [key: string]: any };
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading