1e41f4b71Sopenharmony_ci# @ohos.base (Public Callback Information) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **Base** module defines the public callback types of ArkTS APIs, including the common and error callbacks. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> - 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. 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci> - Since API version 12, the APIs of this module are supported in ArkTS widgets. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## Modules to Import 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci``` 14e41f4b71Sopenharmony_ciimport base from '@ohos.base'; 15e41f4b71Sopenharmony_ci``` 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci## Callback 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ciCallback\<T> { 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci(data: T): void; 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci} 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ciDefines a common callback. 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ciYou can set **data** to customize the data type of the information returned by the callback. 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Base 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description | 34e41f4b71Sopenharmony_ci| ---- | ---- | ---- | -------------------------- | 35e41f4b71Sopenharmony_ci| data | T | Yes | Common callback information.| 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci## ErrorCallback 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ciErrorCallback\<T extends Error = BusinessError> { 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci(err: T): void; 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci} 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ciDefines a common callback that carries an error parameter. 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ciThe information returned by the callback is of the [BusinessError](#businesserror) type. 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Base 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci**Parameters** 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description | 56e41f4b71Sopenharmony_ci| ---- | ---- | ---- | ---------------------------- | 57e41f4b71Sopenharmony_ci| err | T | Yes | Common error information about the API invoking failure.| 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci## AsyncCallback 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ciAsyncCallback\<T, E = void> { 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci(err: BusinessError\<E>, data: T): void; 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci} 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ciDefines a common callback that carries an error parameter and asynchronous return value. 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ciThe error parameter is of the [BusinessError](#businesserror) type. 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ciThe type of the asynchronous return value is defined by the developer. 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Base 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 78e41f4b71Sopenharmony_ci| ---- | ------------------------------------------------------------ | ---- | ---------------------------- | 79e41f4b71Sopenharmony_ci| err | [BusinessError](#businesserror) | Yes | Common error information about the API invoking failure.| 80e41f4b71Sopenharmony_ci| data | T | Yes | Common callback information. | 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci## BusinessError 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ciBusinessError\<T = void> extends Error { 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_cicode: number; 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_cidata?: T; 89e41f4b71Sopenharmony_ci} 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ciDefines the error parameter. 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Base 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 98e41f4b71Sopenharmony_ci| ---- | ------ | ---- | ---------------------------------------------------------- | 99e41f4b71Sopenharmony_ci| code | number | Yes | Common error information about the API invoking failure. | 100e41f4b71Sopenharmony_ci| data | T | No | Common callback information. If this parameter is left empty, no related information is returned.| 101