Table of contents
- 1. Define a window property
- 2. Define a global property
Sometimes you want to define a custom property on the
window namespace. This can be done by declaring it as a global property.
Define a window property
In the following case we want to make TypeScript aware of the property
window.__coverage__ which is set by istanbul’s instrumenter class.
window the TypeScript compiler complains with the following error:
TS2339: Property ‘coverage‘ does not exist on type ‘Window’.
To get along with it we have to make TypeScript aware of this new property by declaring it in our code:
Define a global property
If you want to define a global
__coverage__ property in a Node.js environment, you will have to assign it to the
global object because there is no
window in Node.js: