我使用的角度建立一个项目,我采用了棱角分明-CLI项目的开工,当我尝试运行ng build --prod
我不断收到此错误:角4属性不上Object类型存在于构建
Property 'description' does not exist on type Object
代码生成该错误是:
export class AppComponent {
product: Object = {};
constructor(
private store: StoreService,
private request: RequestService,
) {
this.product = this.request.getProduct(_id);
}
}
<p>{{product.description}}</p>
我读一些有关此内容和错误是因为我使用类型定义来定义产品为对象,但我不传递任何属性定义。
我知道我可以定义一个接口,就像我对数组做的那样,但是我无法做到这一点。我不知道我是否定义错了,这是我的尝试:
export interface ProductInterface {
id: Number;
description: String;
title: String;
}
product: Object<ProductInterface> = {};
但它也给我错误。我需要做什么来避免这种情况?
类型product'的'应该是' ProductInterface',而不是'Object'。 –
谁是getProduct – alehn96