简体   繁体   English

Visual Studio中的Angular 6组件声明编译器错误

[英]Angular 6 Component Declaration compiler error in Visual Studio

I have just upgraded a project from Angular 4 to Angular 6. But I am now getting a compiler error in my Component declarations in Visual Studio. 我刚刚将项目从Angular 4升级到Angular6。但是我现在在Visual Studio的Component声明中遇到编译器错误。 So the following basic declaration is underlined in red: 因此,以下基本声明用红色下划线标出:

@Component({ 
    template: ''
}) 

And on rollover shows the error: 并且在翻转时显示错误:

Argument of type '{ template: string }' is not assignable to parameter of type 'Component' Property 'true' is missing in type '{ template: string }' 类型'{template:string}'的参数不能分配给'Component'类型的参数属性'true'在类型'{template:string}'中丢失

It doesn't matter how complicated this declaration is, whether is has a selector, template url or styles or whatever, it doesn't matter, the error is still there, just longer. 该声明有多复杂,无论是否具有选择器,模板url或样式,等等,都没有关系,该错误仍然存​​在,只是更长的时间。

Now this has zero effect on the app compiling and running, it just shows up as an error in the editor. 现在,这对应用程序的编译和运行影响为零,只是在编辑器中显示为错误。 So it must be a typescript config issue when moving from Angular 4 to Angular 6. When loading the Angular 4 project in Visual Studio, the error does not appear. 因此,从Angular 4迁移到Angular 6时,肯定是一个打字稿配置问题。在Visual Studio中加载Angular 4项目时,不会出现此错误。

I am using Visual Studio 2015, the latest version of the Angular CLI (6.2.3), Typescript 2.8.3 and TsLint 5.11.0. 我正在使用Visual Studio 2015,最新版本的Angular CLI(6.2.3),Typescript 2.8.3和TsLint 5.11.0。

My tsconfig for the project is as follows: 我对该项目的tsconfig如下:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "baseUrl": "src",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "preserveWhitespaces": "off",
    "strictPropertyInitialization": false,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2016",
      "dom"
    ]
  }
}

Any help would be much appreciated. 任何帮助将非常感激。

Cheers John 干杯约翰

Angular 6 has @angular/language-service configured in package.json Angular 6在package.json中配置了@ angular / language-service

This does checks in your IDE that were not done in Angular 4. 这会在您的IDE中检查未在Angular 4中完成的检查。

Because it is very new I think it can get it wrong sometimes, so that might be your problem. 因为它很新,所以我认为有时候它可能会出错,所以这可能是您的问题。

Docs are here: 文件在这里:

https://angular.io/guide/language-service https://angular.io/guide/language-service

I don't use Visual Studio so never seen this but had similar kinds of issue in WebStorm. 我不使用Visual Studio,所以从未见过这种情况,但是WebStorm中存在类似的问题。

Generally, however the language service is good at picking up problems so best keep it enabled. 通常,语言服务擅长解决问题,因此最好将其保持启用状态。 Maybe somehow try and either fix or ignore the error you are getting for now. 也许以某种方式尝试修复或忽略您现在遇到的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM