mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 20:40:20 +00:00
[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:
+7
-1
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user