【发布时间】:2020-07-10 11:13:18
【问题描述】:
我正在将现有的 Angular 7 代码迁移到 Angular 9。我遵循了Angular Upgrade guide。我在组件的 html 模板上收到很多“找不到名称”错误。甚至是 index.html 页面。
这里是有问题的模板:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>My application</title>
<!-- base href is set in angular.json -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="./favicon.ico">
</head>
<body class="style-1">
<!--[if lt IE 9]>
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<app-root></app-root>
</body>
</html>
所有 html 标签和属性都以红线显示,并给我如下错误:-
- 错误:(1, 3) TS2304: 找不到名称'doctype'。
- 错误:(1, 11) TS2304: 找不到名称“html”。
- 错误:(2, 2) TS2304: 找不到名称“html”。
- 错误:(3, 2) TS2304: 找不到名称“head”。
- 错误:(4, 6) TS2304: 找不到名称“元”。
- 错误:(4, 11) TS2304: 找不到名称“字符集”。
- 错误:(4, 19) TS2365: 运算符 '>' 不能应用于类型 “字符串”和“数字”。
- 错误:(5, 6) TS2304: 找不到名称“元”。
等等。
代码中的每一个html模板都是这样的。升级后angular 版本为~9.1.0,typescript 版本为~3.8.3。
即使出现所有这些错误,代码仍然可以正常运行。
我的 tsconfig.json 文件:-
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"downlevelIteration": true,
"outDir": "src/main/webapp/dist",
"paths": {
"app/*": ["src/main/webapp/app/*"]
},
"sourceMap": true,
"declaration": false,
"module": "esnext",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es2015",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
},
"include": [
"src/main/webapp/main.ts",
"src/main/webapp/polyfills.ts",
"src/main/webapp/app"
],
"exclude": [
"node_modules"
]
}
html 上的红线让人分心,我将不胜感激!
【问题讨论】:
-
安装打字并检查
npm install -g typings -
@Kenny typings 是一个已弃用的包。我已经安装了以下软件包:-@types/node、@types/angular、@types/angular-material、@types/html-entities、@types/jquery。我仍然收到错误消息。
标签: angular typescript intellij-idea