【发布时间】:2018-11-04 18:36:00
【问题描述】:
我有一个返回对象/数组的 api,如下所示:
(2) [{...}, {...}] object
0: {a: '1', b: {id: '1'}}
1: {a: '2', b: {id: '2'}}
所以它看起来像对象数组(但调试时说“对象”)。
所以在我的代码中我有:
return this.http.get(this.url).pipe(
map(datas => {
return datas.map(data => {
let object = {
a: data['a'],
b: data['b']['id'],
}
return object;
})
})
);
但是有:
return datas.map(data => {
我遇到了一个错误:
Property 'map' does not exist on type 'Object'.
但应用程序运行良好,可以正确显示此数据。但是这个错误很烦人。
我能做什么?
【问题讨论】:
-
你可以用
(datas: Array<any>) => { ... }告诉Typescript编译器返回值的类型
标签: angular6