Merge pull request #7560 from ManRueda/master

Add support for promise
This commit is contained in:
Masahiro Wakame
2016-01-22 18:05:05 +09:00
2 changed files with 52 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
/// <reference path="promise.d.ts"/>
var prom = new Promise<Boolean>((resolve, reject) => {
resolve(true);
});
var prom2 = new Promise<Boolean>((resolve, reject) => {
resolve(true);
});
prom.then((val) => {
console.log(val);
}).catch(() => {
});
var prom3 = Promise.all([prom, prom2]);
prom3.then((resolve: Array<any>) => {
});
+31
View File
@@ -0,0 +1,31 @@
// Type definitions for promise v7.1.1
// Project: https://www.promisejs.org/
// Definitions by: Manuel Rueda <https://github.com/ManRueda>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Support AMD require
declare module 'promise' {
export = Promise;
}
declare var Promise: Promise.Ipromise;
declare module Promise {
export interface Ipromise {
new <T>(resolver: (resolve: (value: T) => void, reject: (reason: any) => void) => void): IThenable<T>;
resolve: <T>(value: T) => IThenable<T>;
reject: <T>(value: T) => IThenable<T>;
all: (array: Array<IThenable<any>>) => IThenable<Array<any>>;
denodeify: (fn: Function) => IThenable<any>;
nodeify: (fn: Function) => Function;
}
export interface IThenable<T> {
then<R>(onFulfilled?: (value: T) => IThenable<R>|R, onRejected?: (error: any) => IThenable<R>|R): IThenable<R>;
catch<R>(onRejected?: (error: any) => IThenable<R>|R): IThenable<R>;
done<R>(onFulfilled?: (value: T) => IThenable<R>|R, onRejected?: (error: any) => IThenable<R>|R): IThenable<R>;
nodeify<R>(callback: Function): IThenable<R>;
}
}