ArkTSCheck报错:Object literal must match declared class,原因及解决方案?


为什么会出现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站的视频敲的

阅读 115
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
logo
HarmonyOS
子站问答
访问
宣传栏