diff --git a/types/p-cancelable/index.d.ts b/types/p-cancelable/index.d.ts index 4f26cd17ca..775400bca8 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,21 @@ 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; } } 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(); }