我有以下=代码。我想知道这是不是any的恰当用法。我收到了一个关于Unexpected any. Specify a different type @typescript-eslint/no-explicit-any.的警告
但是,如果我将其更改为string。我得到了一个关于map,Property map does not exist on type string.的错误,这个函数完全按照我想要的那样工作。有没有合适的用法,或者有没有办法修复它?
代码
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":[],
} 发布于 2019-12-10 01:30:30
export interface Oceans {
artic: string;
atlantic: string[];
indian: string;
pacific: string[];
southern: string;
}您可以将您的对象模式定义为类似上面的接口,并使用海洋作为“类型”。我需要更多信息,但乍一看,界面似乎是解决方案
https://stackoverflow.com/questions/58870856
复制相似问题