Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 9ccc651

Browse files
committed
Merge pull request #340 from Microsoft/typings
Fixing typings
2 parents a94df48 + 11a963d commit 9ccc651

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "1.11.0-beta",
44
"description": "React Native plugin for the CodePush service",
55
"main": "CodePush.js",
6+
"typings": "typings/react-native-code-push.d.ts",
67
"homepage": "https://microsoft.github.io/code-push",
78
"keywords": [
89
"react-native",

typings/react-native-code-push.d.ts

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
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+
}
719

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;
1022

11-
interface DownloadProgress {
23+
export interface DownloadProgress {
1224
/**
1325
* The total number of bytes expected to be received for this update.
1426
*/
@@ -20,17 +32,17 @@ interface DownloadProgress {
2032
receivedBytes: number;
2133
}
2234

23-
interface LocalPackage extends Package {
35+
export interface LocalPackage extends Package {
2436
/**
2537
* Installs the update by saving it to the location on disk where the runtime expects to find the latest version of the app.
2638
*
2739
* @param installMode Indicates when you would like the update changes to take affect for the end-user.
2840
* @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.
2941
*/
30-
install(installMode: CodePush.InstallMode, minimumBackgroundDuration?: number): ReactNativePromise<void>;
42+
install(installMode: CodePush.InstallMode, minimumBackgroundDuration?: number): Promise<void>;
3143
}
3244

33-
interface Package {
45+
export interface Package {
3446
/**
3547
* The app binary version that this update is dependent on. This is the value that was
3648
* specified via the appStoreVersion parameter when calling the CLI's release command.
@@ -84,21 +96,21 @@ interface Package {
8496
packageSize: number;
8597
}
8698

87-
interface RemotePackage extends Package {
99+
export interface RemotePackage extends Package {
88100
/**
89101
* Downloads the available update from the CodePush service.
90102
*
91103
* @param downloadProgressCallback An optional callback that allows tracking the progress of the update while it is being downloaded.
92104
*/
93-
download(downloadProgressCallback?: DowloadProgressCallback): ReactNativePromise<LocalPackage>;
105+
download(downloadProgressCallback?: DowloadProgressCallback): Promise<LocalPackage>;
94106

95107
/**
96108
* The URL at which the package is available for download.
97109
*/
98110
downloadUrl: string;
99111
}
100112

101-
interface SyncOptions {
113+
export interface SyncOptions {
102114
/**
103115
* Specifies the deployment key you want to query for an update against. By default, this value is derived from the Info.plist
104116
* 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 {
135147
updateDialog?: UpdateDialog;
136148
}
137149

138-
interface UpdateDialog {
150+
export interface UpdateDialog {
139151
/**
140152
* Indicates whether you would like to append the description of an available release to the
141153
* notification message which is displayed to the end user. Defaults to false.
@@ -192,19 +204,19 @@ declare namespace CodePush {
192204
*
193205
* @param deploymentKey The deployment key to use to query the CodePush server for an update.
194206
*/
195-
function checkForUpdate(deploymentKey?: string): ReactNativePromise<RemotePackage>;
207+
function checkForUpdate(deploymentKey?: string): Promise<RemotePackage>;
196208

197209
/**
198210
* Retrieves the metadata for an installed update (e.g. description, mandatory).
199211
*
200212
* @param updateState The state of the update you want to retrieve the metadata for. Defaults to UpdateState.RUNNING.
201213
*/
202-
function getUpdateMetadata(updateState?: UpdateState) : ReactNativePromise<LocalPackage>;
214+
function getUpdateMetadata(updateState?: UpdateState) : Promise<LocalPackage>;
203215

204216
/**
205217
* Notifies the CodePush runtime that an installed update is considered successful.
206218
*/
207-
function notifyAppReady(): ReactNativePromise<void>;
219+
function notifyAppReady(): Promise<void>;
208220

209221
/**
210222
* Immediately restarts the app.
@@ -220,7 +232,7 @@ declare namespace CodePush {
220232
* @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.
221233
* @param downloadProgressCallback An optional callback that allows tracking the progress of an update while it is being downloaded.
222234
*/
223-
function sync(options?: SyncOptions, syncStatusChangedCallback?: SyncStatusChangedCallback, downloadProgressCallback?: DowloadProgressCallback): ReactNativePromise<SyncStatus>;
235+
function sync(options?: SyncOptions, syncStatusChangedCallback?: SyncStatusChangedCallback, downloadProgressCallback?: DowloadProgressCallback): Promise<SyncStatus>;
224236

225237
/**
226238
* Indicates when you would like an installed update to actually be applied.
@@ -321,6 +333,4 @@ declare namespace CodePush {
321333
}
322334
}
323335

324-
declare module "react-native-code-push" {
325-
export default CodePush;
326-
}
336+
export default CodePush;

0 commit comments

Comments
 (0)