标题: const list = Object.keys(allData).map<ClockItem>(key => JSON.parse(allData[key]))报错 Function return type inference is limited [打印本页] 作者: 巫淑倩 时间: 5 天前 标题: const list = Object.keys(allData).map<ClockItem>(key => JSON.parse(allData[key]))报错 Function return type inference is limited [md]### 【问题描述】
1.鸿蒙运行结果、错误
export class ClockItem {
hour: number = 0
minute: number = 0
id: string = ''
reminderId: number = 0
enabled: boolean = false // 是否开启
}
export class ClockStore {
// 1.创建首选项实例
getStore() {
return preferences.getPreferences(getContext(this), 'clockStore')
}
// 3.获取所有闹钟任务数据列表
async getAllClock() {
// 获取实例
const store = await this.getStore()
// 获取所有闹钟任务数据
const allData = await store.getAll()
// 数据转换为数组
const list = Object.keys(allData).map<ClockItem>(key => JSON.parse(allData[key]))
return list
}
}
1. 代码key => JSON.parse(allData[key])报错Function return type inference is limite和Indexed access is not supported for fields
2. 该怎么解决这两个错误