使用TS开发,针对方法传参,可以使用 interface 进行类型约束,比如方法的参数,只支持传 json 对象,并且key限制是string,value限制为string和number,可以实现下述interface实现。
export interface SAEventProperty {
[key: string]: string | number;
}
但是这种实现,在 ArkTS 不允许使用,中会报错Indexed signatures are not supported (arkts-no-indexed-signatures) <ArkTSCheck\>
那么在ArkTS中,怎么实现类似场景的需求呢?
目前不支持此写法,参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/typescript-to-arkts-migration-guide-V5\#不支持index-signature