I have multiple files like:
- library0.js
- library1.js
- ...
- libraryn.js
Each populates part of a global object "MY_GLOBAL" like this example:
library0.js
// check that the MY_GLOBAL namespace exists if (typeof(MY_GLOBAL) === 'undefined') { var MY_GLOBAL = {}; } MY_GLOBAL.TIMEOUT = 120000; // 2 minutes MY_GLOBAL.extractErrMsg = function(reqResponse) { console.log(reqResponse); }; library1.js
// check that the MY_GLOBAL namespace exists if (typeof(MY_GLOBAL) === 'undefined') { var MY_GLOBAL = {}; } MY_GLOBAL.STRING = 'STRING'; MY_GLOBAL.exposed = function() { console.log("This is exposed); }; Currently in my index.html file, I add all these files in script includes. Therefore all my other js files can simple call:
MY_GLOBAL.extractErrMsg or any other function/object on MY_GLOBAL.
I am migrating to TypeScript and I am not sure what to do with this global namespacing. Everywhere I reference the global object MY_GLOBAL, I get error TS2304: Cannot find name 'MY_GLOBAL'. Should I port all these to modules?
Thank you!