Typescript가 이름 창 또는 문서를 찾을 수 없습니다.
두 경우 모두 :
document.getElementById('body');
// or
window.document.getElementById('body');
 
나는 얻다 error TS2304: Cannot find name 'window'.
tsconfig.json설치해야하는 정의 파일 에 누락 된 것이 있습니까?
나는 실행할 때 메시지가 tsc와에서vscode
tsconfig.json :
{
    "compilerOptions": {
        "allowJs": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "jsx": "react",
        "module": "commonjs",
        "moduleResolution": "node",
        "noEmitOnError": true,
        "noImplicitAny": false,
        "sourceMap": true,
        "suppressImplicitAnyIndexErrors": true,
        "target": "ES2016",
        "typeRoots": [
            "node_modules/@types/",
            "typings/index.d.ts"
        ]
    },
    "exclude": [
        "node_modules",
        "**/*-aot.ts"
    ]
}
 
내 답변 : tsconfig.jsonI 대상 es5및 사용과 함께 사용lib: ["es2015", "dom"]
타겟팅으로 인해 문제가 발생한 것 같습니다 ES2016. 
이유가있어서 그것을 목표로 삼고 있습니까? 대상을 지정 es6하면 오류가 사라질 것입니다.
또 다른 옵션은 컴파일러가 사용할 라이브러리를 지정하는 것입니다.
tsc -t ES2016 --lib "ES2016","DOM" ./your_file.ts
 
또한 오류가 사라질 것입니다.
libs가 기본적으로 사용되지 않는 이유는 컴파일러 옵션 문서 에서 --lib옵션에 대해 설명합니다 .
참고 : --lib를 지정하지 않으면 기본 라이브러리가 삽입됩니다. 삽입되는 기본 라이브러리는 다음과 같습니다.
► --target ES5의 경우 : DOM, ES5, ScriptHost
► --target ES6의 경우 : DOM, ES6, DOM.Iterable, ScriptHost
그러나 .NET을 대상으로 할 때 기본 라이브러리가 무엇인지 명시하지 않습니다 ES2016. 
버그 일 수 있습니다. 문제를 열어보십시오. 그렇다면 여기에서 링크를 공유하십시오.
사용하다
"lib": ["dom"]
 
tsconfig.json에서
예 :
{
  "compilerOptions": {
    "lib": ["es5", "es6", "dom"],
    "outDir": "./dist/",
    "sourceMap": true,
    "noImplicitAny": true,
    "module": "commonjs",
    "target": "es6",
    "moduleResolution": "node",
    "jsx": "react"
  },
  "include": ["./src/**/*"]
}
참조 URL : https://stackoverflow.com/questions/41336301/typescript-cannot-find-name-window-or-document
'programing' 카테고리의 다른 글
| angular2 라우터에서 페이지 제목을 변경하는 방법 (0) | 2021.01.13 | 
|---|---|
| Spring Boot Rest 서비스에서 파일 다운로드 (0) | 2021.01.13 | 
| Nginx 프록시 Amazon S3 리소스 (0) | 2021.01.13 | 
| -awakeFromNib 또는 -viewDidLoad를 사용해야합니까? (0) | 2021.01.13 | 
| Java에 포인터가 있습니까? (0) | 2021.01.13 |