在 Angular Typescript 中找不到名称“window”、“localStorage”和其他 DOM 元素

问题描述 投票:0回答:1

(英语不是我的母语) 我很快从 tslint 迁移到 eslist。我都是按照教程做的。之后我得到了一个错误 就像这段代码一样 角度 v(16)

localStorage.removeItem('user');
if (window.location.hostname == 'localhost' || window.location.hostname == '127.0.0.1') {
     this.router.navigateByUrl('/auth/login').then();
}

运行 ng build --source-map=false --watch=true 时出现错误 (IDE webstorm不骂人) 错误 TS2304:找不到名称“localStorage”、“window”

经过一些研究,我发现我已将“dom”放入 tsconfig.json 我做到了,但仍然收到错误 这是 tsconfig.json

{
  "emitDecoratorMetadata": true,
  "compilerOptions": {
    "outDir": "./out-tsc/app",
    "types": [],
    "moduleResolution": "node",
    "target": "ES2022",
    "module": "ES2022",
    "sourceMap": true,
    "declaration": false,
    "useDefineForClassFields": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "forceConsistentCasingInFileNames": true,
    "lib": [
      "ES2022",
      "dom"
    ],
    "paths": {
      "@app/*": [
        "src/app/*"
      ],
      "@environments/*": [
        "src/environments/*"
      ]
    }
  },
  "files": [
    "src/main.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.d.ts"
  ],
  "exclude": [
    "node_modules",
    "src/**/*.spec.ts"
  ],
  "types": [
    "node"
  ]
}
angular typescript dom eslint tslint
1个回答
0
投票

尝试关闭并再次重建项目

© www.soinside.com 2019 - 2024. All rights reserved.