Sometimes, we want to fix TypeScript cannot find name window or document.
In this article, we’ll look at how to fix TypeScript cannot find name window or document.
How to fix TypeScript cannot find name window or document?
To fix TypeScript cannot find name window or document, we should add 'dom'
to the compilerOptions.lib
property in tsconfig.json
.
For instance, we write
{
"compilerOptions": {
"lib": ["es5", "es6", "dom"]
//...
},
"include": ["./src/**/*"]
}
to add the 'dom'
option into the compilerOptions.lib
array in tsconfig.json
so that the TypeScript compiler knows that the browser side global variables are available in our TypeScript project.
Conclusion
To fix TypeScript cannot find name window or document, we should add 'dom'
to the compilerOptions.lib
property in tsconfig.json
.