HarmonyOS 如何自己定义一种结构

Record<"title", string>

想将这个结构定义成ClassA,其他地方可以直接使用ClassA。

HarmonyOS
2025-01-09 15:13:43
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
shlp

参考示例如下:

interface RecordType {
  age: number;
  name: string;
}

type RecordName = 'title';
let recordType: RecordType = { name: 'ZhangSan', age: 5 };
let dataInfo: Record<RecordName, RecordType> = {
  'title': recordType,
};
console.log('打印dataInfo:', JSON.stringify(dataInfo));
console.log("打印结果1:" + JSON.stringify(dataInfo['title']))
console.log("打印结果2:" + JSON.stringify(dataInfo['xxx']));

也可以参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-faqs-V5/faqs-arkts-98-V5

分享
微博
QQ
微信
回复
2025-01-09 17:18:47
相关问题
使用Promise实现一种串行调用方式
1484浏览 • 1回复 待解决
HarmonyOS一种类似总线通知的功能
688浏览 • 1回复 待解决
定义组件如何增加自己的对外方法
2265浏览 • 1回复 待解决