1/* 2 * Copyright (c) 2021-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @file 18 * @kit BasicServicesKit 19 */ 20 21/** 22 * Defines the basic callback. 23 * @typedef Callback 24 * @syscap SystemCapability.Base 25 * @since 6 26 */ 27/** 28 * Defines the basic callback. 29 * @typedef Callback 30 * @syscap SystemCapability.Base 31 * @crossplatform 32 * @since 10 33 */ 34/** 35 * Defines the basic callback. 36 * @typedef Callback 37 * @syscap SystemCapability.Base 38 * @crossplatform 39 * @atomicservice 40 * @since 11 41 */ 42/** 43 * Defines the basic callback. 44 * @typedef Callback<T> 45 * @syscap SystemCapability.Base 46 * @crossplatform 47 * @form 48 * @atomicservice 49 * @since 12 50 */ 51export interface Callback<T> { 52 /** 53 * Defines the callback info. 54 * @param { T } data 55 * @syscap SystemCapability.Base 56 * @since 6 57 */ 58 /** 59 * Defines the callback info. 60 * @param { T } data 61 * @syscap SystemCapability.Base 62 * @crossplatform 63 * @since 10 64 */ 65 /** 66 * Defines the callback info. 67 * @param { T } data 68 * @syscap SystemCapability.Base 69 * @crossplatform 70 * @atomicservice 71 * @since 11 72 */ 73 /** 74 * Defines the callback info. 75 * @param { T } data 76 * @syscap SystemCapability.Base 77 * @crossplatform 78 * @form 79 * @atomicservice 80 * @since 12 81 */ 82 (data: T): void; 83} 84 85/** 86 * Defines the basic error callback. 87 * @typedef ErrorCallback 88 * @syscap SystemCapability.Base 89 * @since 6 90 */ 91/** 92 * Defines the basic error callback. 93 * @typedef ErrorCallback 94 * @syscap SystemCapability.Base 95 * @crossplatform 96 * @since 10 97 */ 98/** 99 * Defines the basic error callback. 100 * @typedef ErrorCallback<T extends Error = BusinessError> 101 * @syscap SystemCapability.Base 102 * @crossplatform 103 * @atomicservice 104 * @since 11 105 */ 106export interface ErrorCallback<T extends Error = BusinessError> { 107 /** 108 * Defines the basic error callback. 109 * @param { T } err 110 * @syscap SystemCapability.Base 111 * @since 6 112 */ 113 /** 114 * Defines the basic error callback. 115 * @param { T } err 116 * @syscap SystemCapability.Base 117 * @crossplatform 118 * @since 10 119 */ 120 /** 121 * Defines the basic error callback. 122 * @param { T } err 123 * @syscap SystemCapability.Base 124 * @crossplatform 125 * @atomicservice 126 * @since 11 127 */ 128 (err: T): void; 129} 130 131/** 132 * Defines the basic async callback. 133 * @typedef AsyncCallback 134 * @syscap SystemCapability.Base 135 * @since 6 136 */ 137/** 138 * Defines the basic async callback. 139 * @typedef AsyncCallback 140 * @syscap SystemCapability.Base 141 * @crossplatform 142 * @since 10 143 */ 144/** 145 * Defines the basic async callback. 146 * @typedef AsyncCallback 147 * @syscap SystemCapability.Base 148 * @crossplatform 149 * @atomicservice 150 * @since 11 151 */ 152/** 153 * Defines the basic async callback. 154 * @typedef AsyncCallback<T, E = void> 155 * @syscap SystemCapability.Base 156 * @crossplatform 157 * @form 158 * @atomicservice 159 * @since 12 160 */ 161export interface AsyncCallback<T, E = void> { 162 /** 163 * Defines the callback data. 164 * @param { BusinessError<E> } err 165 * @param { T } data 166 * @syscap SystemCapability.Base 167 * @since 6 168 */ 169 /** 170 * Defines the callback data. 171 * @param { BusinessError<E> } err 172 * @param { T } data 173 * @syscap SystemCapability.Base 174 * @crossplatform 175 * @since 10 176 */ 177 /** 178 * Defines the callback data. 179 * @param { BusinessError<E> } err 180 * @param { T } data 181 * @syscap SystemCapability.Base 182 * @crossplatform 183 * @atomicservice 184 * @since 11 185 */ 186 /** 187 * Defines the callback data. 188 * @param { BusinessError<E> } err 189 * @param { T } data 190 * @syscap SystemCapability.Base 191 * @crossplatform 192 * @form 193 * @atomicservice 194 * @since 12 195 */ 196 (err: BusinessError<E>, data: T): void; 197} 198 199/** 200 * Defines the error interface. 201 * @typedef BusinessError 202 * @syscap SystemCapability.Base 203 * @since 6 204 */ 205/** 206 * Defines the error interface. 207 * @typedef BusinessError 208 * @syscap SystemCapability.Base 209 * @crossplatform 210 * @since 10 211 */ 212/** 213 * Defines the error interface. 214 * @typedef BusinessError 215 * @syscap SystemCapability.Base 216 * @crossplatform 217 * @atomicservice 218 * @since 11 219 */ 220/** 221 * Defines the error interface. 222 * @extends Error 223 * @typedef BusinessError<T = void> 224 * @syscap SystemCapability.Base 225 * @crossplatform 226 * @form 227 * @atomicservice 228 * @since 12 229 */ 230export interface BusinessError<T = void> extends Error { 231 /** 232 * Defines the basic error code. 233 * @type { number } code 234 * @syscap SystemCapability.Base 235 * @since 6 236 */ 237 /** 238 * Defines the basic error code. 239 * @type { number } code 240 * @syscap SystemCapability.Base 241 * @crossplatform 242 * @since 10 243 */ 244 /** 245 * Defines the basic error code. 246 * @type { number } code 247 * @syscap SystemCapability.Base 248 * @crossplatform 249 * @atomicservice 250 * @since 11 251 */ 252 /** 253 * Defines the basic error code. 254 * @type { number } code 255 * @syscap SystemCapability.Base 256 * @crossplatform 257 * @form 258 * @atomicservice 259 * @since 12 260 */ 261 code: number; 262 /** 263 * Defines the additional information for business 264 * @type { ?T } data 265 * @syscap SystemCapability.Base 266 * @since 9 267 */ 268 /** 269 * Defines the additional information for business 270 * @type { ?T } data 271 * @syscap SystemCapability.Base 272 * @crossplatform 273 * @since 10 274 */ 275 /** 276 * Defines the additional information for business 277 * @type { ?T } data 278 * @syscap SystemCapability.Base 279 * @crossplatform 280 * @atomicservice 281 * @since 11 282 */ 283 /** 284 * Defines the additional information for business 285 * @type { ?T } data 286 * @syscap SystemCapability.Base 287 * @crossplatform 288 * @form 289 * @atomicservice 290 * @since 12 291 */ 292 data?: T; 293} 294