Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals) <ArkTSCheck
这个错误提示表明您正在创建一个对象字面量,但它没有与任何明确声明的类或接口相对应。
// 没有头像数据的接口
interface HeroInfo {
id: number
name: string
title: string
}
// 有头像数据的接口
interface HeroInfoPlus {
id: number
name: string
title: string
avatar: ResourceStr
}
const arr: HeroInfo[] = [
{ id: 123, name: '吕布', title: '无双之魔' },
{ id: 124, name: '周瑜', title: '铁血都督' },
{ id: 126, name: '夏侯惇', title: '不羁之风' },
{ id: 127, name: '甄姬', title: '洛神降临' },
{ id: 128, name: '曹操', title: '鲜血枭雄' }
]
//map映射数组
arr.map((item) => {
return {}
})
解决
// 没有头像数据的接口
interface HeroInfo {
id: number
name: string
title: string
}
// 有头像数据的接口
interface HeroInfoPlus {
id: number
name: string
title: string
avatar: ResourceStr
}
const arr: HeroInfo[] = [
{ id: 123, name: '吕布', title: '无双之魔' },
{ id: 124, name: '周瑜', title: '铁血都督' },
{ id: 126, name: '夏侯惇', title: '不羁之风' },
{ id: 127, name: '甄姬', title: '洛神降临' },
{ id: 128, name: '曹操', title: '鲜血枭雄' }
]
//map映射数组
arr.map<HeroInfoPlus>((item) => {
return {}
})