mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-03 11:41:44 +00:00
promise-polyfill types
This commit is contained in:
Vendored
+23
@@ -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));
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user