• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 *
24 * @typedef { Callback<T> }
25 * @syscap SystemCapability.Base
26 * @crossplatform
27 * @form
28 * @atomicservice
29 * @since 20
30 */
31export type Callback<T> = (data: T) => void;
32
33/**
34 * Defines the basic error callback.
35 *
36 * @typedef { ErrorCallback<T extends Error = BusinessError> }
37 * @syscap SystemCapability.Base
38 * @crossplatform
39 * @atomicservice
40 * @since 20
41 */
42export type ErrorCallback<T extends Error = BusinessError> = (err: T)=> void;
43
44/**
45 * Defines the basic async callback.
46 *
47 * @typedef { AsyncCallback<T, E = void> }
48 * @syscap SystemCapability.Base
49 * @crossplatform
50 * @form
51 * @atomicservice
52 * @since 20
53 */
54export type AsyncCallback<T, E = void> = (err: BusinessError<E> | null, data: T | undefined)=> void;
55
56/**
57 * Defines the error interface.
58 * @syscap SystemCapability.Base
59 * @crossplatform
60 * @form
61 * @atomicservice
62 * @since 20
63 */
64export declare class BusinessError<T = void> extends Error {
65  /**
66  * A constructor used to create a BusinessError object
67  * @syscap SystemCapability.Base
68  * @crossplatform
69  * @form
70  * @atomicservice
71  * @since 20
72  */
73  constructor();
74  /**
75  * A constructor used to create a BusinessError object
76  * @param { number } code
77  * @param { Error } error
78  * @syscap SystemCapability.Base
79  * @crossplatform
80  * @form
81  * @atomicservice
82  * @since 20
83  */
84  constructor(code: number, error: Error);
85  /**
86  * A constructor used to create a BusinessError object
87  * @param { number } code
88  * @param { T } data
89  * @param { Error } error
90  * @syscap SystemCapability.Base
91  * @crossplatform
92  * @form
93  * @atomicservice
94  * @since 20
95  */
96  constructor(code: number, data: T, error: Error);
97  /**
98   * Defines the basic error code.
99   * @type { number } code
100   * @syscap SystemCapability.Base
101   * @since 6
102   */
103  /**
104   * Defines the basic error code.
105   * @type { number } code
106   * @syscap SystemCapability.Base
107   * @crossplatform
108   * @since 10
109   */
110  /**
111   * Defines the basic error code.
112   * @type { number } code
113   * @syscap SystemCapability.Base
114   * @crossplatform
115   * @atomicservice
116   * @since 11
117   */
118  /**
119   * Defines the basic error code.
120   * @type { number } code
121   * @syscap SystemCapability.Base
122   * @crossplatform
123   * @form
124   * @atomicservice
125   * @since 12
126   */
127   /**
128   * Defines the basic error code.
129   * @type { number } code
130   * @syscap SystemCapability.Base
131   * @crossplatform
132   * @form
133   * @atomicservice
134   * @since 20
135   */
136  code: number;
137  /**
138   * Defines the additional information for business
139   * @type { ?T } data
140   * @syscap SystemCapability.Base
141   * @since 9
142   */
143  /**
144   * Defines the additional information for business
145   * @type { ?T } data
146   * @syscap SystemCapability.Base
147   * @crossplatform
148   * @since 10
149   */
150  /**
151   * Defines the additional information for business
152   * @type { ?T } data
153   * @syscap SystemCapability.Base
154   * @crossplatform
155   * @atomicservice
156   * @since 11
157   */
158  /**
159   * Defines the additional information for business
160   * @type { ?T } data
161   * @syscap SystemCapability.Base
162   * @crossplatform
163   * @form
164   * @atomicservice
165   * @since 12
166   */
167   /**
168   * Defines the additional information for business
169   * @type { ?T } data
170   * @syscap SystemCapability.Base
171   * @crossplatform
172   * @form
173   * @atomicservice
174   * @since 20
175   */
176  data?: T;
177}
178
179 /**
180  * In ArkTS static typing, for literals where the hierarchy and the number
181  * of attributes per level are uncertain, you can use RecordData for initialization.
182  * @typedef RecordData
183  * @syscap SystemCapability.Base
184  * @since 20
185  * @example
186  * import { RecordData } from '@kit.BasicServiceKit';
187  * const param: RecordData = {
188  *   "key": {
189  *   "a": 1
190  *   }
191  * }
192  * let want: Want = {
193  *   bundleName: 'com.example.myapplication',
194  *   abilityName: 'EntryAbility',
195  *   parameters: param
196  * };
197  * this.context.startAbility(want);
198  */
199 export type RecordData = undefined | null | Object | Record<string, RecordData> | Array<RecordData>;
200