如何解决ArkTSCheck报错:Object literal must correspond to some explicitly declared class or interface?

关于Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals) <ArkTSCheck> 报错

// Define the message sync trigger types
type MsgSyncTriggerTypeUnique = "poll" | "longlink" | "wakeup" | "newlongink" | "pushwakeup";

// Export the message sync trigger types
export const MsgSyncTriggerType = {
  POLL: "poll" as MsgSyncTriggerTypeUnique,
  LONG_LINK: "longlink" as MsgSyncTriggerTypeUnique,
  WAKE_UP: "wakeup" as MsgSyncTriggerTypeUnique,
  NEW_LONG_LINK: "newlongink" as MsgSyncTriggerTypeUnique,
  WAKE_UP_PUSH: "pushwakeup" as MsgSyncTriggerTypeUnique,
};

这样定义类型报错:Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals) <ArkTSCheck>

本文参与了思否 HarmonyOS 技术问答马拉松,欢迎正在阅读的你也加入。
阅读 2.8k
1 个回答

ArkTS在TS基础商机进行了约束,不支持对象类型中包含call signature。
这种情况可以定义为一种枚举:

export enum MsgSyncTriggerType {
  POLL = "poll",
  LONG_LINK = "longlink",
  WAKE_UP = "wakeup",
  NEW_LONG_LINK = "newlongink",
  WAKE_UP_PUSH = "pushwakeup"
}
本文参与了思否 HarmonyOS 技术问答马拉松,欢迎正在阅读的你也加入。
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
logo
HarmonyOS
子站问答
访问
宣传栏