From 01924ef872642806278dff62f03f5ebca37594c5 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Mon, 24 Jul 2017 17:54:38 +0200 Subject: [PATCH] [promise.prototype.finally] add typings for the non-shim variant (#18114) * [promise.prototype.finally] add typings for the non-shim variant of promise.prototype.finally * [promise.prototype.finally] change indentation to 4 spaces * [promise.prototype.finally] fix lint error --- types/promise.prototype.finally/index.d.ts | 8 +++++++- .../promise.prototype.finally-tests.ts | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/types/promise.prototype.finally/index.d.ts b/types/promise.prototype.finally/index.d.ts index 5c4581ba46..a2db2ef22a 100644 --- a/types/promise.prototype.finally/index.d.ts +++ b/types/promise.prototype.finally/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for promise.prototype.finally 2.0 // Project: https://github.com/matthew-andrews/Promise.prototype.finally // Definitions by: Slava Shpitalny +// BendingBender // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare global { @@ -9,4 +10,9 @@ declare global { } } -export function shim(): void; +export = promiseFinally; + +declare function promiseFinally(promise: Promise, onFinally?: () => U | PromiseLike): Promise; +declare namespace promiseFinally { + function shim(): void; +} diff --git a/types/promise.prototype.finally/promise.prototype.finally-tests.ts b/types/promise.prototype.finally/promise.prototype.finally-tests.ts index 2fa7c96512..bbbb2ce390 100644 --- a/types/promise.prototype.finally/promise.prototype.finally-tests.ts +++ b/types/promise.prototype.finally/promise.prototype.finally-tests.ts @@ -3,7 +3,7 @@ import promiseFinally = require('promise.prototype.finally'); promiseFinally.shim(); let promise = new Promise((resolve, reject) => { - resolve(true); + resolve(true); }); promise.finally(() => {}); @@ -13,3 +13,20 @@ promise.catch(() => {}).finally(() => {}); let allPromise = Promise.all([promise]); allPromise.finally(() => {}); + +const resolved = Promise.resolve(42); +const rejected = Promise.reject(-1); + +let num: number; +promiseFinally(resolved, () => Promise.resolve(true)) + .then(x => num = x); + +promiseFinally(resolved, () => > Promise.resolve(true)) + .then(x => num = x); + +promiseFinally(rejected, () => false) + .catch(e => num = e); + +let bool: boolean; +promiseFinally(rejected, () => {throw false; }) + .catch(e => bool = e);