From fc8f08bf522beff3d87df89983a9903e05876aa1 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 13 Jan 2017 10:49:38 -0800 Subject: [PATCH] React native promise (#13952) * Remove duplicate Promise definiton from react-native * Update AsyncStorageStatic definitions to match implementation * Review comments * fix return type --- react-native/index.d.ts | 116 ++++------------------------------------ 1 file changed, 10 insertions(+), 106 deletions(-) diff --git a/react-native/index.d.ts b/react-native/index.d.ts index 3bb716d1db..c9a9b76dc5 100644 --- a/react-native/index.d.ts +++ b/react-native/index.d.ts @@ -21,102 +21,6 @@ export = React; //react-native "extends" react declare module "react" { - /** - * Represents the completion of an asynchronous operation - * @see lib.es6.d.ts - */ - export interface Promise { - /** - * Attaches callbacks for the resolution and/or rejection of the Promise. - * @param onfulfilled The callback to execute when the Promise is resolved. - * @param onrejected The callback to execute when the Promise is rejected. - * @returns A Promise for the completion of which ever callback is executed. - */ - then(onfulfilled?: (value: T) => TResult | Promise, onrejected?: (reason: any) => TResult | Promise): Promise; - - /** - * Attaches a callback for only the rejection of the Promise. - * @param onrejected The callback to execute when the Promise is rejected. - * @returns A Promise for the completion of the callback. - */ - catch(onrejected?: (reason: any) => T | Promise): Promise; - - - // not in lib.es6.d.ts but called by react-native - done(callback?: (value: T) => void): void; - } - - export interface PromiseConstructor { - /** - * A reference to the prototype. - */ - prototype: Promise; - - /** - * Creates a new Promise. - * @param init A callback used to initialize the promise. This callback is passed two arguments: - * a resolve callback used resolve the promise with a value or the result of another promise, - * and a reject callback used to reject the promise with a provided reason or error. - */ - new (init: (resolve: (value?: T | Promise) => void, reject: (reason?: any) => void) => void): Promise; - - (init: (resolve: (value?: T | Promise) => void, reject: (reason?: any) => void) => void): Promise; - - /** - * Creates a Promise that is resolved with an array of results when all of the provided Promises - * resolve, or rejected when any Promise is rejected. - * @param values An array of Promises. - * @returns A new Promise. - */ - all(values: (T | Promise)[]): Promise; - - /** - * Creates a Promise that is resolved with an array of results when all of the provided Promises - * resolve, or rejected when any Promise is rejected. - * @param values An array of values. - * @returns A new Promise. - */ - all(values: Promise[]): Promise; - - /** - * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved - * or rejected. - * @param values An array of Promises. - * @returns A new Promise. - */ - race(values: (T | Promise)[]): Promise; - - /** - * Creates a new rejected promise for the provided reason. - * @param reason The reason the promise was rejected. - * @returns A new rejected Promise. - */ - reject(reason: any): Promise; - - /** - * Creates a new rejected promise for the provided reason. - * @param reason The reason the promise was rejected. - * @returns A new rejected Promise. - */ - reject(reason: any): Promise; - - /** - * Creates a new resolved promise for the provided value. - * @param value A promise. - * @returns A promise whose internal state matches the provided promise. - */ - resolve(value: T | Promise): Promise; - - /** - * Creates a new resolved promise . - * @returns A resolved promise. - */ - resolve(): Promise; - } - - // @see lib.es6.d.ts - export var Promise: PromiseConstructor; - export type MeasureOnSuccessCallback = ( x: number, y: number, @@ -5634,7 +5538,7 @@ declare module "react" { * Fires when a user has finished scrolling. */ onScrollEndDrag?: (event?: NativeSyntheticEvent) => void - + /** * Fires when scroll view has finished moving */ @@ -6132,43 +6036,43 @@ declare module "react" { /** * Sets value for key and calls callback on completion, along with an Error if there is any */ - setItem(key: string, value: string, callback?: (error?: Error) => void): Promise + setItem(key: string, value: string, callback?: (error?: Error) => void): Promise - removeItem(key: string, callback?: (error?: Error) => void): Promise + removeItem(key: string, callback?: (error?: Error) => void): Promise /** * Merges existing value with input value, assuming they are stringified json. Returns a Promise object. * Not supported by all native implementation */ - mergeItem(key: string, value: string, callback?: (error?: Error) => void): Promise + mergeItem(key: string, value: string, callback?: (error?: Error) => void): Promise /** * Erases all AsyncStorage for all clients, libraries, etc. You probably don't want to call this. * Use removeItem or multiRemove to clear only your own keys instead. */ - clear(callback?: (error?: Error) => void): Promise + clear(callback?: (error?: Error) => void): Promise /** * Gets all keys known to the app, for all callers, libraries, etc */ - getAllKeys(callback?: (error?: Error, keys?: string[]) => void): Promise + getAllKeys(callback?: (error?: Error, keys?: string[]) => void): Promise /** * multiGet invokes callback with an array of key-value pair arrays that matches the input format of multiSet */ - multiGet(keys: string[], callback?: (errors?: Error[], result?: string[][]) => void): Promise + multiGet(keys: string[], callback?: (errors?: Error[], result?: [string, string][]) => void): Promise<[string, string][]> /** * multiSet and multiMerge take arrays of key-value array pairs that match the output of multiGet, * * multiSet([['k1', 'val1'], ['k2', 'val2']], cb); */ - multiSet(keyValuePairs: string[][], callback?: (errors?: Error[]) => void): Promise + multiSet(keyValuePairs: string[][], callback?: (errors?: Error[]) => void): Promise /** * Delete all the keys in the keys array. */ - multiRemove(keys: string[], callback?: (errors?: Error[]) => void): Promise + multiRemove(keys: string[], callback?: (errors?: Error[]) => void): Promise /** * Merges existing values with input values, assuming they are stringified json. @@ -6176,7 +6080,7 @@ declare module "react" { * * Not supported by all native implementations. */ - multiMerge(keyValuePairs: string[][], callback?: (errors?: Error[]) => void): Promise + multiMerge(keyValuePairs: string[][], callback?: (errors?: Error[]) => void): Promise } export type BackPressEventName = "hardwareBackPress"