From 27a1db59ce14906a5a6d86d3e0a06adacecd5c2c Mon Sep 17 00:00:00 2001 From: Steve Jenkins Date: Tue, 15 Nov 2016 14:30:59 +0000 Subject: [PATCH] promise-polyfill types --- promise-polyfill/index.d.ts | 23 ++++++++++++++++++++++ promise-polyfill/promise-polyfill-tests.ts | 18 +++++++++++++++++ promise-polyfill/tsconfig.json | 19 ++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 promise-polyfill/index.d.ts create mode 100644 promise-polyfill/promise-polyfill-tests.ts create mode 100644 promise-polyfill/tsconfig.json diff --git a/promise-polyfill/index.d.ts b/promise-polyfill/index.d.ts new file mode 100644 index 0000000000..442e8461ec --- /dev/null +++ b/promise-polyfill/index.d.ts @@ -0,0 +1,23 @@ +// Type definitions for promise v6.0.2 +// Project: https://www.npmjs.com/package/promise-polyfill +// Definitions by: Steve Jenkins +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export as namespace Promise; + +export = Promise; +declare var Promise: Promise.IPromise; + +declare namespace Promise { + export interface IPromise { + new (resolver: (resolve: (value: T) => void, reject: (reason: any) => void) => void): IThenable; + resolve: (value: T) => IThenable; + reject: (value: T) => IThenable; + all: (array: Array>) => IThenable>; + } + + export interface IThenable { + then(onFulfilled?: (value: T) => IThenable|R, onRejected?: (error: any) => IThenable|R): IThenable; + catch(onRejected?: (error: any) => IThenable|R): IThenable; + } +} diff --git a/promise-polyfill/promise-polyfill-tests.ts b/promise-polyfill/promise-polyfill-tests.ts new file mode 100644 index 0000000000..280a2bebdf --- /dev/null +++ b/promise-polyfill/promise-polyfill-tests.ts @@ -0,0 +1,18 @@ +const prom1 = new Promise((resolve, reject) => { + resolve(12); +}); + +const prom2 = new Promise((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)); \ No newline at end of file diff --git a/promise-polyfill/tsconfig.json b/promise-polyfill/tsconfig.json new file mode 100644 index 0000000000..d411c896d5 --- /dev/null +++ b/promise-polyfill/tsconfig.json @@ -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" + ] +} \ No newline at end of file