Zorbing icon

promise.d.ts

Zorbing | PRO | 10/18/15 03:12:33 AM UTC | 0 ⭐ | 10057 👁️ | Never ⏰ | []
ECMAScript |

4.03 KB

|

None

|

0 👍

/

0 👎

// Type definitions for promise 7.0.4
// Project: https://www.npmjs.com/package/promise
// Code base: https://github.com/borisyankov/DefinitelyTyped/blob/35119c83fe214d18c7e370a678cd85dfcfbfa42a/es6-promise/es6-promise.d.ts
// Definitions by: François de Campredon <https://github.com/fdecampredon/>, vvakame <https://github.com/vvakame>
// Adapted by: Zorbing <https://github.com/Zorbing>
 
/* =================== USAGE ===================
 
    import * as Promise from "promise";
 
 =============================================== */
 
declare module Promise
{
    interface Thenable<R>
    {
        then<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => U | Thenable<U>): Thenable<U>;
        then<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => void): Thenable<U>;
    }
    
    interface Instance<R>
    {
        /**
         * onFulfilled is called when/if "promise" resolves. onRejected is called when/if "promise" rejects.
         * Both are optional, if either/both are omitted the next onFulfilled/onRejected in the chain is called.
         * Both callbacks have a single parameter , the fulfillment value or rejection reason.
         * "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve.
         * If an error is thrown in the callback, the returned promise rejects with that error.
         *
         * @param onFulfilled called when/if "promise" resolves
         * @param onRejected called when/if "promise" rejects
         */
        then<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => U | Thenable<U>): Instance<U>;
        then<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => void): Instance<U>;
        
        /**
         * Sugar for promise.then(undefined, onRejected)
         *
         * @param onRejected called when/if "promise" rejects
         */
        catch<U>(onRejected?: (error: any) => U | Thenable<U>): Instance<U>;
        
        done<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => U | Thenable<U>): void;
        done<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => void): void;
        
        finally<U>(onFulfilled?: (value?: R | Thenable<R>) => Instance<R>): Instance<U>;
        
        nodeify(callback: (error: any, value?: R) => void, context: any): Instance<R> | void;
    }
    
    interface Static
    {
        /**
         * If you call resolve in the body of the callback passed to the constructor,
         * your promise is fulfilled with result object passed to resolve.
         * If you call reject your promise is rejected with the object passed to resolve.
         * For consistency and debugging (eg stack traces), obj should be an instanceof Error.
         * Any errors thrown in the constructor callback will be implicitly passed to reject().
         */
        new <R>(callback: (resolve : (value?: R | Thenable<R>) => void, reject: (error?: any) => void) => void): Instance<R>
        
        /**
         * Make a new promise from the thenable.
         * A thenable is promise-like in as far as it has a "then" method.
         */
        resolve<T>(value?: T | Thenable<T>): Instance<T>;
        
        /**
         * Make a promise that rejects to obj. For consistency and debugging (eg stack traces), obj should be an instanceof Error
         */
        reject(error: any): Instance<any>;
        
        /**
         * Make a promise that fulfills when every item in the array fulfills, and rejects if (and when) any item rejects.
         * the array passed to all can be a mixture of promise-like objects and other objects.
         * The fulfillment value is an array (in order) of fulfillment values. The rejection value is the first rejection value.
         */
        all<T>(promises: (T | Thenable<T>)[]): Instance<T[]>;
        
        /**
         * Make a Promise that fulfills when any item fulfills, and rejects if any item rejects.
         */
        race<T>(promises: (T | Thenable<T>)[]): Instance<T>;
        
        denodeify<T>(fn: Function, argumentCount?: number): (...args: any[]) => Instance<T>;
        nodeify<T>(fn: Function): (...args: any[]) => Instance<T> | any;
    }
}
 
 
declare module "promise"
{
    export = promise;
}
 
declare var promise: Promise.Static;

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎