[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
This commit is contained in:
Dimitri Benin
2017-07-24 08:54:38 -07:00
committed by Andy
parent 64099f0b4c
commit 01924ef872
2 changed files with 25 additions and 2 deletions
+7 -1
View File
@@ -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 <https://github.com/slavik57>
// BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare global {
@@ -9,4 +10,9 @@ declare global {
}
}
export function shim(): void;
export = promiseFinally;
declare function promiseFinally<T, U>(promise: Promise<T>, onFinally?: () => U | PromiseLike<U>): Promise<T>;
declare namespace promiseFinally {
function shim(): void;
}
@@ -3,7 +3,7 @@ import promiseFinally = require('promise.prototype.finally');
promiseFinally.shim();
let promise = new Promise<boolean>((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, () => <PromiseLike<boolean>> 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);