1

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.

6
  • Please add your tsconfig.json to your question, even if it's in the link Commented Mar 22, 2017 at 11:16
  • 1
    Possible duplicate of Use window object in angular2 but vscode "Cannot find name 'window' " Commented Mar 22, 2017 at 11:16
  • Your tsconfig.json must have "dom" Commented Mar 22, 2017 at 13:13
  • 1
    can you try after adding "declare var window: any;" in you code Commented Mar 22, 2017 at 13:27
  • are you sure you add compilerOptions in tsconfig.json as compilerOptions property,not the root json. Commented Mar 22, 2017 at 14:27

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
0

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
  }
}

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.