1
- // Type definitions for React Native CodePush module.
2
- // Project: https://github.com/Microsoft/react-native-code-push
3
-
4
- /// <reference path="../react-native/react-native.d.ts" />
5
-
6
- import ReactNativePromise = __React . Promise ;
1
+ // Define an interal interface for Promise, so that
2
+ // we don't need to reference an additional d.ts file.
3
+ interface Promise < T > {
4
+ /**
5
+ * Append a rejection handler callback to the promise.
6
+ *
7
+ * @param onRejected Callback to be triggered when the promise is rejected.
8
+ */
9
+ catch ( onRejected ?: ( reason : any ) => Promise < T > ) : Promise < T > ;
10
+
11
+ /**
12
+ * Append a fulfillment and/or rejection handler to the promise.
13
+ *
14
+ * @param onFulfilled Callback to be triggered when the promise is fulfilled.
15
+ * @param onRejected Callback to be triggered when the promise is rejected.
16
+ */
17
+ then ( onFulfilled ?: ( value : T ) => void , onRejected ?: ( reason : any ) => Promise < T > ) : Promise < T > ;
18
+ }
7
19
8
- type DowloadProgressCallback = ( progress : DownloadProgress ) => void ;
9
- type SyncStatusChangedCallback = ( status : CodePush . SyncStatus ) => void ;
20
+ export type DowloadProgressCallback = ( progress : DownloadProgress ) => void ;
21
+ export type SyncStatusChangedCallback = ( status : CodePush . SyncStatus ) => void ;
10
22
11
- interface DownloadProgress {
23
+ export interface DownloadProgress {
12
24
/**
13
25
* The total number of bytes expected to be received for this update.
14
26
*/
@@ -20,17 +32,17 @@ interface DownloadProgress {
20
32
receivedBytes : number ;
21
33
}
22
34
23
- interface LocalPackage extends Package {
35
+ export interface LocalPackage extends Package {
24
36
/**
25
37
* Installs the update by saving it to the location on disk where the runtime expects to find the latest version of the app.
26
38
*
27
39
* @param installMode Indicates when you would like the update changes to take affect for the end-user.
28
40
* @param minimumBackgroundDuration For resume-based installs, this specifies the number of seconds the app needs to be in the background before forcing a restart. Defaults to 0 if unspecified.
29
41
*/
30
- install ( installMode : CodePush . InstallMode , minimumBackgroundDuration ?: number ) : ReactNativePromise < void > ;
42
+ install ( installMode : CodePush . InstallMode , minimumBackgroundDuration ?: number ) : Promise < void > ;
31
43
}
32
44
33
- interface Package {
45
+ export interface Package {
34
46
/**
35
47
* The app binary version that this update is dependent on. This is the value that was
36
48
* specified via the appStoreVersion parameter when calling the CLI's release command.
@@ -84,21 +96,21 @@ interface Package {
84
96
packageSize : number ;
85
97
}
86
98
87
- interface RemotePackage extends Package {
99
+ export interface RemotePackage extends Package {
88
100
/**
89
101
* Downloads the available update from the CodePush service.
90
102
*
91
103
* @param downloadProgressCallback An optional callback that allows tracking the progress of the update while it is being downloaded.
92
104
*/
93
- download ( downloadProgressCallback ?: DowloadProgressCallback ) : ReactNativePromise < LocalPackage > ;
105
+ download ( downloadProgressCallback ?: DowloadProgressCallback ) : Promise < LocalPackage > ;
94
106
95
107
/**
96
108
* The URL at which the package is available for download.
97
109
*/
98
110
downloadUrl : string ;
99
111
}
100
112
101
- interface SyncOptions {
113
+ export interface SyncOptions {
102
114
/**
103
115
* Specifies the deployment key you want to query for an update against. By default, this value is derived from the Info.plist
104
116
* file (iOS) and MainActivity.java file (Android), but this option allows you to override it from the script-side if you need to
@@ -135,7 +147,7 @@ interface SyncOptions {
135
147
updateDialog ?: UpdateDialog ;
136
148
}
137
149
138
- interface UpdateDialog {
150
+ export interface UpdateDialog {
139
151
/**
140
152
* Indicates whether you would like to append the description of an available release to the
141
153
* notification message which is displayed to the end user. Defaults to false.
@@ -192,19 +204,19 @@ declare namespace CodePush {
192
204
*
193
205
* @param deploymentKey The deployment key to use to query the CodePush server for an update.
194
206
*/
195
- function checkForUpdate ( deploymentKey ?: string ) : ReactNativePromise < RemotePackage > ;
207
+ function checkForUpdate ( deploymentKey ?: string ) : Promise < RemotePackage > ;
196
208
197
209
/**
198
210
* Retrieves the metadata for an installed update (e.g. description, mandatory).
199
211
*
200
212
* @param updateState The state of the update you want to retrieve the metadata for. Defaults to UpdateState.RUNNING.
201
213
*/
202
- function getUpdateMetadata ( updateState ?: UpdateState ) : ReactNativePromise < LocalPackage > ;
214
+ function getUpdateMetadata ( updateState ?: UpdateState ) : Promise < LocalPackage > ;
203
215
204
216
/**
205
217
* Notifies the CodePush runtime that an installed update is considered successful.
206
218
*/
207
- function notifyAppReady ( ) : ReactNativePromise < void > ;
219
+ function notifyAppReady ( ) : Promise < void > ;
208
220
209
221
/**
210
222
* Immediately restarts the app.
@@ -220,7 +232,7 @@ declare namespace CodePush {
220
232
* @param syncStatusChangedCallback An optional callback that allows tracking the status of the sync operation, as opposed to simply checking the resolved state via the returned Promise.
221
233
* @param downloadProgressCallback An optional callback that allows tracking the progress of an update while it is being downloaded.
222
234
*/
223
- function sync ( options ?: SyncOptions , syncStatusChangedCallback ?: SyncStatusChangedCallback , downloadProgressCallback ?: DowloadProgressCallback ) : ReactNativePromise < SyncStatus > ;
235
+ function sync ( options ?: SyncOptions , syncStatusChangedCallback ?: SyncStatusChangedCallback , downloadProgressCallback ?: DowloadProgressCallback ) : Promise < SyncStatus > ;
224
236
225
237
/**
226
238
* Indicates when you would like an installed update to actually be applied.
@@ -321,6 +333,4 @@ declare namespace CodePush {
321
333
}
322
334
}
323
335
324
- declare module "react-native-code-push" {
325
- export default CodePush ;
326
- }
336
+ export default CodePush ;
0 commit comments