【关键字】
ArkTSCheck
【问题描述】
ArkTSCheck检查不允许使用any,catch这种情况不知道该指定什么类型,其中startAbility是一个异步操作方法。
ability.context.startAbility(wantInfo)
.then(() => {
LogUtil.logD(`打开成功`);
})
.catch((err) => {
LogUtil.logD(`打开失败:${JSON.stringify(err)}`);
}
)
【解决方案】
ArkTS不支持any、undefined和unknown类型,err应显示指定类型
示例如下:
import { BusinessError } from '@ohos.base';
async function errorDemo() { }
errorDemo().catch((err:BusinessError)=>{ err.code err.name })