javascripttypescriptvisual-studio-code.d.ts

Global type declaration in vscode for javascript


I have a /typings/$app.d.ts looks like this.

declare class App {
    test: object
}

export const $app: App;

enter image description here

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?

enter image description here


Solution

  • 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;