promise-polyfill types

This commit is contained in:
Steve Jenkins
2016-11-15 14:30:59 +00:00
parent b4c0da5e19
commit 27a1db59ce
3 changed files with 60 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
// Type definitions for promise v6.0.2
// Project: https://www.npmjs.com/package/promise-polyfill
// Definitions by: Steve Jenkins <https://github.com/skysteve>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export as namespace Promise;
export = Promise;
declare var Promise: Promise.IPromise;
declare namespace 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>>;
}
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>;
}
}
@@ -0,0 +1,18 @@
const prom1 = new Promise<number>((resolve, reject) => {
resolve(12);
});
const prom2 = new Promise<string>((resolve, reject) => {
reject('an error');
}).then((val) => {
console.log(val);
return val;
}).catch((err) => {
console.error(err);
});
Promise.all([prom1, prom2])
.then(result => {
console.log(result);
}, (exception) => console.error(exception))
.catch((ex) => console.error(ex));
+19
View File
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"promise-polyfill-tests.ts"
]
}