为什么会出现Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals) <ArkTSCheck>这个错误,求大佬解释一下
代码:
async selectAllRecord(): Promise<RecordVO[]> {
let rps = await RecordModel.queryAll()
return rps.map(rp => {
//将RecordPO对象转换成RecordVO
let rv:RecordVO = {id: rp.id, keepId: rp.keepId, amount: rp.amount, successAmount: rp.successAmount, createTime: rp.createTime} as RecordVO
//通过ID查询RecordItem对象
rv.recordItem = RecordItemModel.getById(rp.keepId)
//计算卡路里
rv.calorie = rp.amount * rv.recordItem.calorie
return rv
})
}
代码里的RecordVO[]是:
export default class RecordVO {
//记录ID
id: number;
//运动ID
keepId: number;
//消耗卡路里
calorie: number;
//记录运动信息
recordItem: RecordItem
//运动时长或个数
amount: number = 0;
//已完成运动时长或个数
successAmount: number = 0;
//记录日期
createTime: number;
constructor(id: number, keepId: number, calorie: number, amount:number, successAmount: number,createTime: number) {
this.id = id;
this.keepId = keepId;
this.calorie = calorie;
this.amount = amount;
this.successAmount = successAmount;
this.createTime = createTime;
this.recordItem = RecordItemModel.getById(this.keepId)
}
}
刚接触鸿蒙不是很懂,按B站的视频敲的