下面有一个类似的类,它实现了一个IBData接口。
export class BModel implements IBData{
}在API响应之后,我将数据分配给私有变量accountBalanceData,它的类型为IBData。
this.accountBalanceData = data; 我从api响应调用获得的数据是BModel类型的,即类本身。
我得到了下面的error
[ts] Type 'BModel[]' is not assignable to type 'IBData'.
[ts]
Type 'BModel[]' is not assignable to type 'IBData'.
Property 'getAcBal' is missing in type 'BModel[]'.我尝试了下面的typecast
this.accountBalanceData = data as IBData; 我得到了下面的error
[ts] Type 'BModel[]' cannot be converted to type 'IBData'.
[ts]
Type 'BModel[]' cannot be converted to type 'IBData'.
Property 'getAcBal' is missing in type 'BModel[]'.更新:
.map(res => {
res["_body"] = res["_body"].replace(/[\n\r\t]+/g,"");
this.BModel.data = res["_body"]
return this.BModel;
}) 发布于 2017-01-19 11:37:56
函数map返回一个对象数组,因此该表达式的结果类型
.map(res => {
res["_body"] = res["_body"].replace(/[\n\r\t]+/g,"");
this.BModel.data = res["_body"]
return this.BModel;
}) 将是BModel[]
https://stackoverflow.com/questions/41739601
复制相似问题