xxxxxxxxxx
// @ts-ignore
console.log("globalThis.myVar: "+globalThis.myVar);
// This will ignore the error typescript gives when using globalThis
Applies to TypeScript 4.3+
xxxxxxxxxx
declare global {
function myFunction(): boolean;
var myVariable: number;
}
globalThis.myFunction = () => true;
globalThis.myVariable = 42;
IMPORTANT: This solution only works by declaring variables with var (do not use let or const).