Table of contents
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.
When calling __coverage__
on 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:
1 |
|
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:
1 |
|