• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.base (Public Callback Information)
2
3The **Base** module defines the public callback types of ArkTS APIs, including the common and error callbacks.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9## Modules to Import
10
11```
12import base from '@ohos.base';
13```
14
15## Callback
16
17Callback\<T> {
18
19(data: T): void;
20
21}
22
23Defines a common callback.
24
25You can set **data** to customize the data type of the information returned by the callback.
26
27**System capability**: SystemCapability.Base
28
29| Name| Type| Mandatory| Description                      |
30| ---- | ---- | ---- | -------------------------- |
31| data | T    | Yes  | Common callback information.|
32
33## ErrorCallback
34
35ErrorCallback\<T extends Error = BusinessError> {
36
37(err: T): void;
38
39}
40
41Defines a common callback that carries an error parameter.
42
43The information returned by the callback is of the [BusinessError](#businesserror) type.
44
45**System capability**: SystemCapability.Base
46
47**Parameters**
48
49| Name| Type| Mandatory| Description                        |
50| ---- | ---- | ---- | ---------------------------- |
51| err  | T    | Yes  | Common error information about the API invoking failure.|
52
53## AsyncCallback
54
55AsyncCallback\<T, E = void> {
56
57(err: BusinessError, data: T): void;
58
59}
60
61Defines a common callback that carries an error parameter and asynchronous return value.
62
63The error parameter is of the [BusinessError](#businesserror) type.
64
65The type of the asynchronous return value is defined by the developer.
66
67**System capability**: SystemCapability.Base
68
69| Name| Type                                                        | Mandatory| Description                        |
70| ---- | ------------------------------------------------------------ | ---- | ---------------------------- |
71| err  | [BusinessError](#businesserror) | Yes  | Common error information about the API invoking failure.|
72| data | T                                                            | Yes  | Common callback information.  |
73
74## BusinessError
75
76BusinessError\<T = void> extends Error {
77
78code: number;
79
80data?: T;
81}
82
83Defines the error parameter.
84
85**System capability**: SystemCapability.Base
86
87| Name| Type  | Mandatory| Description                                                      |
88| ---- | ------ | ---- | ---------------------------------------------------------- |
89| code | number | Yes  | Common error information about the API invoking failure.                            |
90| data | T      | No  | Common callback information. If this parameter is left empty, no related information is returned.|
91