Currently, I am utilizing TypeScript for type checking of JS files. This involves adding a // @ts-check
comment at the beginning of the file. However, I am encountering an issue with a global variable that has been assigned separately using window
.
// index.js
window.MY_GLOBAL_VARIABLE = 42;
// module.js
console.log(MY_GLOBAL_VARIABLE); // Error: Cannot find name 'MY_GLOBAL_VARIABLE'.
I have attempted to alleviate this error by including the following comments:
/*
declare var MY_GLOBAL_VARIABLE: number
*/
as well as
/*
declare global {
var MY_GLOBAL_VARIABLE: number
}
*/
Furthermore, I have also tried adding these declarations to a global.d.ts
file. Despite my efforts, the checker continues to flag the error.
If anyone knows a solution to rectify this issue, please share your insights.