未验证 提交 3f87ec2a 编写于 作者: O openharmony_ci 提交者: Gitee

!23520 【ArkTs整改】批量修改场景---无法自动推导出的类型;没有指定类型的初始化,catch 明确错误码类型

Merge pull request !23520 from junyi233/gaojing
......@@ -136,10 +136,10 @@ struct BasketViewer {
build() {
Column() {
ForEach(this.shopBasket,
(item) => {
(item:PurchaseItem) => {
Text(`Price: ${item.price.toFixed(2)} €`)
},
item => item.id.toString()
(item:PurchaseItem) => item.id.toString()
)
Text(`Total: ${this.totalPurchase.toFixed(2)} €`)
}
......
......@@ -16,8 +16,9 @@
```ts
import installer from '@ohos.bundle.installer';
import { BusinessError } from '@ohos.base';
let bundleName = 'com.ohos.demo';
let installParam = {
let installParam: installer.InstallParam = {
userId: 100
};
......@@ -30,11 +31,12 @@ try {
console.info('uninstall successfully.');
}
});
}).catch(error => {
}).catch((error: BusinessError) => {
console.error('getBundleInstaller failed. Cause: ' + error.message);
});
} catch (error) {
console.error('getBundleInstaller failed. Cause: ' + error.message);
let message = (error as BusinessError).message;
console.error('getBundleInstaller failed. Cause: ' + message);
}
```
......
......@@ -165,6 +165,7 @@ preloads列表配置的moduleName对应的[moduleType(模块类型)](../referenc
```ts
import router from '@ohos.router';
import { BusinessError } from '@ohos.base';
@Entry
@Component
......@@ -196,7 +197,7 @@ struct Index {
url: '@bundle:com.example.hmservice/library/ets/pages/menu'
}).then(() => {
console.log("push page success");
}).catch(err => {
}).catch((err: BusinessError) => {
console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`);
})
})
......
......@@ -82,7 +82,8 @@ export function foo2() {
import native from "libnative.so"
export function nativeMulti(a: number, b: number) {
return native.multi(a, b);
let result: number = native.multi(a, b);
return result;
}
```
......
......@@ -23,7 +23,7 @@ library
```ts
// library/src/main/ets/utils/test.ts
export class Log {
static info(msg) {
static info(msg: string) {
console.info(msg);
}
}
......@@ -119,7 +119,8 @@ export { ResManager } from './ResManager'
import native from "libnative.so"
export function nativeMulti(a: number, b: number) {
return native.multi(a, b);
let result: number = native.multi(a, b);
return result;
}
```
......@@ -194,6 +195,7 @@ struct Index {
若开发者想在entry模块中,添加一个按钮跳转至library模块中的menu页面(路径为:`library/src/main/ets/pages/menu.ets`),那么可以在使用方的代码(entry模块下的Index.ets,路径为:`entry/src/main/ets/MainAbility/Index.ets`)里这样使用:
```ts
import router from '@ohos.router';
import { BusinessError } from '@ohos.base';
@Entry
@Component
......@@ -225,7 +227,7 @@ struct Index {
url: '@bundle:com.example.hmservice/library/ets/pages/menu'
}).then(() => {
console.log("push page success");
}).catch(err => {
}).catch((err: BusinessError) => {
console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`);
})
})
......
......@@ -1020,9 +1020,10 @@ queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), userId: numbe
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
let want: Want = {
bundleName : "com.example.myapplication",
abilityName : "EntryAbility"
};
......@@ -1078,8 +1079,9 @@ queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), callback: Asy
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let want = {
let want: Want = {
bundleName : "com.example.myapplication",
abilityName : "EntryAbility"
};
......@@ -1142,9 +1144,10 @@ queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), userId?: numb
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
let want: Want = {
bundleName : "com.example.myapplication",
abilityName : "EntryAbility"
};
......@@ -1165,8 +1168,9 @@ try {
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let want = {
let want: Want = {
bundleName : "com.example.myapplication",
abilityName : "EntryAbility"
};
......@@ -1227,9 +1231,10 @@ queryAbilityInfoSync(want: Want, abilityFlags: [number](#abilityflag), userId?:
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
let want: Want = {
bundleName : "com.example.myapplication",
abilityName : "EntryAbility"
};
......@@ -1248,8 +1253,9 @@ try {
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let want = {
let want: Want = {
bundleName : "com.example.myapplication",
abilityName : "EntryAbility"
};
......@@ -1302,10 +1308,11 @@ queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityTyp
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
let want: Want = {
bundleName : "com.example.myapplication",
abilityName : "EntryAbility"
};
......@@ -1361,9 +1368,10 @@ queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityTyp
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let want = {
let want: Want = {
bundleName : "com.example.myapplication",
abilityName : "EntryAbility"
};
......@@ -1426,11 +1434,12 @@ queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityTyp
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
let want: Want = {
bundleName : "com.example.myapplication",
abilityName : "EntryAbility"
};
......@@ -1451,9 +1460,10 @@ try {
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let want = {
let want: Want = {
bundleName : "com.example.myapplication",
abilityName : "EntryAbility"
};
......@@ -1514,11 +1524,12 @@ queryExtensionAbilityInfoSync(want: Want, extensionAbilityType: [ExtensionAbilit
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
let want: Want = {
bundleName : "com.example.myapplication",
abilityName : "EntryAbility"
};
......@@ -1536,9 +1547,10 @@ try {
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let want = {
let want: Want = {
bundleName : "com.example.myapplication",
abilityName : "EntryAbility"
};
......@@ -2140,18 +2152,18 @@ setAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), isE
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
let want: Want = {
bundleName : "com.example.myapplication",
abilityName : "EntryAbility"
};
let info;
try {
bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo));
info = abilitiesInfo[0];
let info = abilitiesInfo[0];
bundleManager.setAbilityEnabled(info, false, err => {
if (err) {
......@@ -2209,18 +2221,18 @@ setAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), isE
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
let want: Want = {
bundleName : "com.example.myapplication",
abilityName : "EntryAbility"
};
let info;
try {
bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo));
info = abilitiesInfo[0];
let info = abilitiesInfo[0];
bundleManager.setAbilityEnabled(info, false).then(() => {
hilog.info(0x0000, "testTag", "setAbilityEnabled successfully.");
......@@ -2270,26 +2282,27 @@ setAbilityEnabledSync(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md),
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
let want: Want = {
bundleName : "com.example.myapplication",
abilityName : "EntryAbility"
};
let info;
try {
bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo));
info = abilitiesInfo[0];
let info = abilitiesInfo[0];
try {
bundleManager.setAbilityEnabledSync(info, false);
hilog.info(0x0000, "testTag", "setAbilityEnabledSync successfully.");
} catch (err) {
hilog.error(0x0000, 'testTag', 'setAbilityEnabledSync failed: %{public}s', err.message);
let message = (err as BusinessError).message;
hilog.error(0x0000, 'testTag', 'setAbilityEnabledSync failed: %{public}s', message);
}
}).catch(err => {
}).catch((err: BusinessError) => {
hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
});
} catch (err) {
......@@ -2474,18 +2487,18 @@ isAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), call
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
let want: Want = {
bundleName : "com.example.myapplication",
abilityName : "EntryAbility"
};
let info;
try {
bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo));
info = abilitiesInfo[0];
let info = abilitiesInfo[0];
bundleManager.isAbilityEnabled(info, (err, data) => {
if (err) {
......@@ -2540,25 +2553,25 @@ isAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md)): Pro
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
let want: Want = {
bundleName : "com.example.myapplication",
abilityName : "EntryAbility"
};
let info;
try {
bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo));
info = abilitiesInfo[0];
let info = abilitiesInfo[0];
bundleManager.isAbilityEnabled(info).then((data) => {
hilog.info(0x0000, 'testTag', 'isAbilityEnabled successfully. Data: %{public}s', JSON.stringify(data));
}).catch(err => {
}).catch((err: BusinessError) => {
hilog.error(0x0000, 'testTag', 'isAbilityEnabled failed. Cause: %{public}s', err.message);
});
}).catch(err => {
}).catch((err: BusinessError) => {
hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
});
} catch (err) {
......@@ -2604,26 +2617,27 @@ isAbilityEnabledSync(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md)):
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
let want: Want = {
bundleName : "com.example.myapplication",
abilityName : "EntryAbility"
};
let info;
try {
bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo));
info = abilitiesInfo[0];
let info = abilitiesInfo[0];
try {
let data = bundleManager.isAbilityEnabledSync(info);
hilog.info(0x0000, 'testTag', 'isAbilityEnabledSync successfully: %{public}s', JSON.stringify(data));
} catch (err) {
hilog.error(0x0000, 'testTag', 'isAbilityEnabledSync failed: %{public}s', err.message);
let message = (err as BusinessError).message;
hilog.error(0x0000, 'testTag', 'isAbilityEnabledSync failed: %{public}s', message);
}
}).catch(err => {
}).catch((err: BusinessError) => {
hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
});
} catch (err) {
......@@ -2833,11 +2847,12 @@ getLaunchWantForBundleSync(bundleName: string, userId?: number): Want;
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let bundleName = 'com.example.myapplication';
let userId = 100;
try {
let want = bundleManager.getLaunchWantForBundleSync(bundleName, userId);
let want: Want = bundleManager.getLaunchWantForBundleSync(bundleName, userId);
hilog.info(0x0000, 'testTag', 'getLaunchWantForBundleSync successfully. Data: %{public}s', JSON.stringify(want));
} catch (err) {
let message = (err as BusinessError).message;
......@@ -2849,11 +2864,12 @@ try {
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let bundleName = 'com.example.myapplication';
let userId = 100;
try {
let want = bundleManager.getLaunchWantForBundleSync(bundleName);
let want: Want = bundleManager.getLaunchWantForBundleSync(bundleName);
hilog.info(0x0000, 'testTag', 'getLaunchWantForBundleSync successfully. Data: %{public}s', JSON.stringify(want));
} catch (err) {
let message = (err as BusinessError).message;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册