I have a /typings/$app.d.ts looks like this.
declare class App {
test: object
}
export const $app: App;

But in order to use the intellisense, I have to auto-import it and it will generate a line like this on the first line of my javascript code.
import { $app } from "../../typings/$app";
It will get in some error since it's a d.ts file.
Is there a way to make this $app.d.ts global like how the window does?

declare var something in .d.ts file top level scope is the keyword to expose global variable. Don't do export if you don't want to export anything.
declare class App {
test: object
}
declare var $app: App;
I would like to make a comment on @hackape 's answer and also recommend (if you haven't already) to add a tsconfig.json file to your project's root. Note that you can also add tsconfig if you don't want to use any typescript (only for intellisense).
You can have a minimal file like this:
{
"compilerOptions": {
"allowJs": true,
"typeRoots": ["./typings"],
"outFile": "./justANameToMakeTSHappy.js"
}
}
allowJs - so vscode would know to use the types also in the JS files. typeRoots - let ts know where your types are. outFile - so you don't get the error of 'can't overwrite file ****.js'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With