I'm in the process of creating TypeScript type definitions for a library that is developed with webpack and is designed to be loaded into the global window object. This library is specifically made for easy integration into the browser using a CDN.
After some research, I found that defining a `Window` interface and including the library in it should allow my definition to be merged with the existing global `Window` definition within an IDE. While this method works when I include the `.d.ts` file as a library in WebStorm, it doesn't seem to work properly with VSCode.
Here's a basic example from my `my-lib.d.ts` file:
export interface Window {
mylib: MyLib
}
export class MyLib {
foo(): string;
bar: number;
}
This is how I intend to access it in `consuming-script.js`:
/// <reference path="my-lib.d.ts"/>
const result = window.mylib.foo();
While the import reference functions correctly (I can access the `MyLib` class), IntelliSense does not display the `mylib` property on the `window` object as expected.
Although adding a global declaration in `my-lib.d.ts` does work, it exposes `mylib` globally rather than under the `window` object, which is not the preferred approach.
Am I missing something? Is there a specific setting in Visual Studio Code that needs to be adjusted? It seems odd that it's so straightforward in WebStorm but problematic in VSCode, considering TS is a Microsoft language utilized in a Microsoft IDE.