Zorbing

promise.d.ts

Oct 17th, 2015
10,361
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Type definitions for promise 7.0.4
  2. // Project: https://www.npmjs.com/package/promise
  3. // Code base: https://github.com/borisyankov/DefinitelyTyped/blob/35119c83fe214d18c7e370a678cd85dfcfbfa42a/es6-promise/es6-promise.d.ts
  4. // Definitions by: François de Campredon <https://github.com/fdecampredon/>, vvakame <https://github.com/vvakame>
  5. // Adapted by: Zorbing <https://github.com/Zorbing>
  6.  
  7. /* =================== USAGE ===================
  8.  
  9.     import * as Promise from "promise";
  10.  
  11.  =============================================== */
  12.  
  13. declare module Promise
  14. {
  15.     interface Thenable<R>
  16.     {
  17.         then<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => U | Thenable<U>): Thenable<U>;
  18.         then<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => void): Thenable<U>;
  19.     }
  20.    
  21.     interface Instance<R>
  22.     {
  23.         /**
  24.          * onFulfilled is called when/if "promise" resolves. onRejected is called when/if "promise" rejects.
  25.          * Both are optional, if either/both are omitted the next onFulfilled/onRejected in the chain is called.
  26.          * Both callbacks have a single parameter , the fulfillment value or rejection reason.
  27.          * "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve.
  28.          * If an error is thrown in the callback, the returned promise rejects with that error.
  29.          *
  30.          * @param onFulfilled called when/if "promise" resolves
  31.          * @param onRejected called when/if "promise" rejects
  32.          */
  33.         then<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => U | Thenable<U>): Instance<U>;
  34.         then<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => void): Instance<U>;
  35.        
  36.         /**
  37.          * Sugar for promise.then(undefined, onRejected)
  38.          *
  39.          * @param onRejected called when/if "promise" rejects
  40.          */
  41.         catch<U>(onRejected?: (error: any) => U | Thenable<U>): Instance<U>;
  42.        
  43.         done<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => U | Thenable<U>): void;
  44.         done<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => void): void;
  45.        
  46.         finally<U>(onFulfilled?: (value?: R | Thenable<R>) => Instance<R>): Instance<U>;
  47.        
  48.         nodeify(callback: (error: any, value?: R) => void, context: any): Instance<R> | void;
  49.     }
  50.    
  51.     interface Static
  52.     {
  53.         /**
  54.          * If you call resolve in the body of the callback passed to the constructor,
  55.          * your promise is fulfilled with result object passed to resolve.
  56.          * If you call reject your promise is rejected with the object passed to resolve.
  57.          * For consistency and debugging (eg stack traces), obj should be an instanceof Error.
  58.          * Any errors thrown in the constructor callback will be implicitly passed to reject().
  59.          */
  60.         new <R>(callback: (resolve : (value?: R | Thenable<R>) => void, reject: (error?: any) => void) => void): Instance<R>
  61.        
  62.         /**
  63.          * Make a new promise from the thenable.
  64.          * A thenable is promise-like in as far as it has a "then" method.
  65.          */
  66.         resolve<T>(value?: T | Thenable<T>): Instance<T>;
  67.        
  68.         /**
  69.          * Make a promise that rejects to obj. For consistency and debugging (eg stack traces), obj should be an instanceof Error
  70.          */
  71.         reject(error: any): Instance<any>;
  72.        
  73.         /**
  74.          * Make a promise that fulfills when every item in the array fulfills, and rejects if (and when) any item rejects.
  75.          * the array passed to all can be a mixture of promise-like objects and other objects.
  76.          * The fulfillment value is an array (in order) of fulfillment values. The rejection value is the first rejection value.
  77.          */
  78.         all<T>(promises: (T | Thenable<T>)[]): Instance<T[]>;
  79.        
  80.         /**
  81.          * Make a Promise that fulfills when any item fulfills, and rejects if any item rejects.
  82.          */
  83.         race<T>(promises: (T | Thenable<T>)[]): Instance<T>;
  84.        
  85.         denodeify<T>(fn: Function, argumentCount?: number): (...args: any[]) => Instance<T>;
  86.         nodeify<T>(fn: Function): (...args: any[]) => Instance<T> | any;
  87.     }
  88. }
  89.  
  90.  
  91. declare module "promise"
  92. {
  93.     export = promise;
  94. }
  95.  
  96. declare var promise: Promise.Static;
Advertisement