LondonBoy
LondonBoy

Reputation: 149

TypeScript Cannot find name 'window'

In my Meteor/React project I have the following line:

let gameId = window.prompt("Please enter the ID of the game you wish to load.");

TypeScript gives the transpiling error Cannot find name 'window'. I am using barbatus/typescript, with default compiler options:

{ "module": "commonjs", "target": "es5", "moduleResolution": "node", "experimentalDecorators": true, "emitDecoratorMetadata": true, "sourceMap": true }

I tried creating a tsconfig.json in the root of my Meteor project, copying the above compiler options but appending the line:

"lib": ["es2015", "dom"]

However, the error remains.

Upvotes: 1

Views: 8771

Answers (2)

Renato
Renato

Reputation: 1

In addition to the answer above in your tsconfig file, you need to set the "lib" property to include "dom".

{
  "compilerOptions": {
    // rest of your config
    "lib": ["dom"] // Add this line
  }
}

Upvotes: 0

Joy Yu
Joy Yu

Reputation: 21

I added "dom" to the lib compilerOptions in tsconfig.json,then this problem has been resolved.

Upvotes: 2

Related Questions