From 5f178511caeb96021fa64676f560b658a8340d8c Mon Sep 17 00:00:00 2001 From: Kendra Knittel Date: Thu, 23 Aug 2018 14:22:14 -0400 Subject: [PATCH 1/3] Make p-cancellable types compatible with 0.5 - Append `onCancel` instead of prepending (https://github.com/sindresorhus/p-cancelable/commit/8e3aaec245492f3a38b5d4f74e9861cf3f334616) - Rename `PCancelable.canceled` to `PCancelable.isCanceled` (https://github.com/sindresorhus/p-cancelable/commit/433d25c8fcf08acd127f0249bc8377379c98363c) - Add `CancelError.isCanceled` (https://github.com/sindresorhus/p-cancelable/commit/ad14c228a9c53f939ed6de068cfe83b5fa27fe1c) - Add ability to provide cancel reason (https://github.com/sindresorhus/p-cancelable/commit/a97b12b309f7ab60f8bfa22883b052c17b32a04e) --- types/p-cancelable/index.d.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/types/p-cancelable/index.d.ts b/types/p-cancelable/index.d.ts index 4f26cd17ca..bfa30c1fd8 100644 --- a/types/p-cancelable/index.d.ts +++ b/types/p-cancelable/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for p-cancelable 0.3 +// Type definitions for p-cancelable 0.5 // Project: https://github.com/sindresorhus/p-cancelable#readme // Definitions by: BendingBender // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -11,20 +11,22 @@ interface PCancelableConstructor extends PromiseConstructor { readonly prototype: PCancelable.PCancelable; readonly CancelError: PCancelable.CancelErrorConstructor; fn(wrapper: (onCancel: (fn?: () => void) => void, input: T) => PromiseLike): (input: T) => PCancelable.PCancelable; - new(executor: (onCancel: (fn?: () => void) => void, resolve: (value?: T | PromiseLike) => void, reject: (reason?: any) => void) => void): PCancelable.PCancelable; + new(executor: (resolve: (value?: T | PromiseLike) => void, reject: (reason?: any) => void, onCancel: (fn?: () => void) => void) => void): PCancelable.PCancelable; } declare namespace PCancelable { interface PCancelable extends Promise { - readonly canceled: boolean; - cancel(): void; + readonly isCanceled: boolean; + cancel(reason?: string): void; + } interface CancelErrorConstructor extends ErrorConstructor { - new (): CancelError; + new (reason?: string): CancelError; } interface CancelError extends Error { readonly name: 'CancelError'; + readonly isCanceled: boolean; } } From beacb0dee8904a20b8806f5f94c5279e3f2065b7 Mon Sep 17 00:00:00 2001 From: Kendra Knittel Date: Thu, 23 Aug 2018 14:42:56 -0400 Subject: [PATCH 2/3] Update p-cancelable-tests.ts --- types/p-cancelable/p-cancelable-tests.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/p-cancelable/p-cancelable-tests.ts b/types/p-cancelable/p-cancelable-tests.ts index ca5f728e18..8bd3790e08 100644 --- a/types/p-cancelable/p-cancelable-tests.ts +++ b/types/p-cancelable/p-cancelable-tests.ts @@ -3,7 +3,7 @@ import PCancelableCtor = require('p-cancelable'); import { EventEmitter } from "events"; -const cancelablePromise: PCancelableCtor.PCancelable<{}> = new PCancelableCtor((onCancel, resolve, reject) => { +const cancelablePromise: PCancelableCtor.PCancelable<{}> = new PCancelableCtor((resolve, reject, onCancel) => { class Worker extends EventEmitter { close() { } @@ -24,7 +24,7 @@ cancelablePromise console.log('Operation finished successfully:', value); }) .catch(reason => { - if (cancelablePromise.canceled) { + if (cancelablePromise.isCanceled) { // Handle the cancelation here console.log('Operation was canceled'); return; @@ -56,7 +56,7 @@ const fn = PCancelableCtor.fn((onCancel: (fn?: () => void) => void, input: strin const promise = fn('input'); let num: number; promise.then(innum => num = innum); -if (!promise.canceled) { +if (!promise.isCanceled) { promise.cancel(); } From 5780ef042932f95803c90cc66597788c48f90e61 Mon Sep 17 00:00:00 2001 From: Kendra Knittel Date: Thu, 23 Aug 2018 14:53:45 -0400 Subject: [PATCH 3/3] Remove stray newline --- types/p-cancelable/index.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/types/p-cancelable/index.d.ts b/types/p-cancelable/index.d.ts index bfa30c1fd8..775400bca8 100644 --- a/types/p-cancelable/index.d.ts +++ b/types/p-cancelable/index.d.ts @@ -18,7 +18,6 @@ declare namespace PCancelable { interface PCancelable extends Promise { readonly isCanceled: boolean; cancel(reason?: string): void; - } interface CancelErrorConstructor extends ErrorConstructor {