Categories
TypeScript Answers

How to fix TypeScript cannot find name window or document?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *