启用了fullTemplateTypeCheck和strictTemplates的Angular 9:类型上不存在属性

时间:2020-02-07 15:51:46

标签: angular angular9

我有一个类似

的组件
import { Component } from '@angular/core';

interface ItemBaseType {
   foo: boolean;
}

interface ItemType extends ItemBaseType {
   bar: boolean;
}

@Component({
  selector: 'ac-foo',
  template: `<div *ngIf="item.bar">Hello</div>`,
})
export class FooComponent {
   public item: ItemType;
}

我已在Angular 9应用上启用fullTemplateTypeCheck and strictTemplates ,并且在运行ng serve时引发异常:

类型“ ItemBaseType”上不存在属性“栏”。

但是bar存在于ItemType上。

出了什么问题?

1 个答案:

答案 0 :(得分:1)

在这种情况下,您可以使用item..bar。希望对您有所帮助。