Add PromiseLike-compatible type for then (#28866)

This commit is contained in:
Benjamin Lichtman
2018-09-13 16:51:00 -07:00
committed by Andy
parent f6466f9257
commit 1221ff85a0
2 changed files with 4 additions and 1 deletions

2
types/q/index.d.ts vendored
View File

@@ -61,7 +61,7 @@ declare namespace Q {
* The then method from the Promises/A+ specification, with an additional progress handler.
*/
then<U>(onFulfill?: ((value: T) => IWhenable<U>) | null, onReject?: ((error: any) => IWhenable<U>) | null, onProgress?: ((progress: any) => any) | null): Promise<U>;
then<U = T, V = never>(onFulfill?: ((value: T) => IWhenable<U>) | null, onReject?: ((error: any) => IWhenable<V>) | null, onProgress?: ((progress: any) => any) | null): Promise<U | V>;
/**
* Like a finally clause, allows you to observe either the fulfillment or rejection of a promise, but to do so
* without modifying the final value. This is useful for collecting resources regardless of whether a job succeeded,

View File

@@ -245,6 +245,9 @@ Q.try(() => {
})
.catch((error) => console.error("Couldn't sync to the cloud", error));
// ensure Q.Promise is compatible with PromiseLike
const p7: PromiseLike<void> = Q.Promise<void>((resolve) => resolve());
// thenReject, returning a Promise of the same type as the Promise it is called on
function thenRejectSameType(arg: any): Q.Promise<number> {
if (!arg) {