我有一个场景,在 promiseAll
下,我发送两个请求,并在 then
块中组合响应返回,因此我需要定义两个数据类型。我是这样定义的
Promise.all<FirstType[], SecondType>([this.firstAPIHit, this.secondAPIHit(Id)]).then((data: [FirstType[], SecondType]): void => {
FirstType
是 Array List
例如:[{Id: 1, Name: "Test"}, {Id: 2, Name: "Random"}] >
SecondType
是 object
例如:{Id: "12345", city: null, location: Array(1)}
作为一项功能,它在 Angular 8 之前运行良好,但我最近将其迁移到 Angular 11 并开始抛出错误
0:0 error Parsing error: Cannot read property 'map' of undefined
调试后我发现如果我删除此类型声明,则会立即删除错误。但我不认为删除它。
在相同的上下文中我可以将两者分配给同一个变量有什么帮助吗?
响应包含 data---> (2) [Array(3), {…}]
新编辑:
我在其他地方也发现了同样的错误,我发现我像下面这样定义的地方现在显示错误:
abc: [number, string][]
private myFunction(chart): [IChartData[], number, number] {...}
希望它可以帮助某人回答我的问题!