【发布时间】:2017-05-29 13:26:33
【问题描述】:
我正在尝试使用泛型在打字稿中创建以下函数,但它向我显示以下错误:
“'CustomerInterface' 类型上不存在属性 'id'” 这发生在:customer.id === +id
getCustomer<CustomerInterface>(id: number | string){
return this.getCustomers<CustomerInterface>('')
.then(customers => customers.find(customer => customer.id === +id));
}
接口定义:
export interface CustomerInterface {
id: number
name: string
display_name: string
address: string
city: string
phone_number: string
}
【问题讨论】:
-
您可以添加错误的屏幕截图以及导致的行。还有你的 customer 对象是什么?
标签: angular generics typescript