【发布时间】:2020-03-11 05:49:33
【问题描述】:
我有以下 = 代码。我想知道这是否是 any 的适当使用。我收到了 Unexpected any. Specify a different type @typescript-eslint/no-explicit-any. 的 lint 警告
但是,如果我将其更改为字符串。我收到地图错误,Property map does not exist on type string. 该功能完全按照我的意愿工作。是否适用于 ANY 或有办法解决它?
代码
function flatMapArr(object: Array<any>): Array<string> {
return Object.entries(object).reduce(
(acc: Array<string>, [k, v]) => acc.concat([k, ...v.map((s: Array<string>) => `${s} ${k}`)]),
[],
)
}
采用数组形式
{
"arctic":[],
"atlantic":[
"north",
"south",
],
"indian":[],
"pacific":[
"north",
"south",
],
"southern":[],
}
【问题讨论】:
标签: typescript eslint array.prototype.map