我有以下=代码。我想知道这是否是any的适当用法。我收到Unexpected any. Specify a different type @typescript-eslint/no-explicit-any.
但是,如果我将其更改为字符串。我在地图上遇到错误,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":[],
}
答案 0 :(得分:0)
export interface Oceans {
artic: string;
atlantic: string[];
indian: string;
pacific: string[];
southern: string;
}
您可以将对象模式定义为上述接口,并将Oceans用作“类型”。我需要更多信息,但乍一看,接口似乎是解决方案