HarmonyOS 类如何实现带有index signature的接口?

1、编写以下代码

import { insightIntent } from '@kit.IntentsKit'

class testClass implements insightIntent.IntentActionInfo {
}

2、报错如下:

Class 'testClass' incorrectly implements interface 'IntentActionInfo'. Index signature for type 'string' is missing in type 'testClass'. <ArkTSCheck>
阅读 435
1 个回答

不支持直接implements insightIntent.IntentActionInfo,参考示例如下:

class testClass implements insightIntent.InsightIntent {
  intentName: string;
  intentVersion: string;
  identifier: string;
  intentActionInfo: insightIntent.IntentActionInfo;
  intentEntityInfo: insightIntent.IntentEntityInfo;

  constructor(intentName: string,
    intentVersion: string,
    identifier: string,
    intentActionInfo: insightIntent.IntentActionInfo,
    intentEntityInfo: insightIntent.IntentEntityInfo) {
    this.intentName = intentName
    this.intentVersion = intentVersion
    this.identifier = identifier
    this.intentActionInfo = intentActionInfo
    this.intentEntityInfo = intentEntityInfo
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进