how can I declare a global variable in typescript
in global.ts
export namespace Global {
export var test: string = 'Hello World!';
}
in your.ts
import { Global } from "./global";
console.log(Global.test)
I try to do that I get the error property ‘test’ does not exist on type ‘Global’.
Create a file globals.d.ts
with
interface Global {
test: string;
}
More
Declaration files : https://basarat.gitbook.io/typescript/docs/types/ambient/d.ts.html