// Type definitions for p-cancelable 0.3
// Project: https://github.com/sindresorhus/p-cancelable#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

export = PCancelable;

declare const PCancelable: PCancelableConstructor;

interface PCancelableConstructor extends PromiseConstructor {
    readonly prototype: PCancelable.PCancelable<any>;
    readonly CancelError: PCancelable.CancelErrorConstructor;
    fn<T, R>(wrapper: (onCancel: (fn?: () => void) => void, input: T) => PromiseLike<R>): (input: T) => PCancelable.PCancelable<R>;
    new<T>(executor: (onCancel: (fn?: () => void) => void, resolve: (value?: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): PCancelable.PCancelable<T>;
}

declare namespace PCancelable {
    interface PCancelable<T> extends Promise<T> {
        readonly canceled: boolean;
        cancel(): void;
    }

    interface CancelErrorConstructor extends ErrorConstructor {
        new (): CancelError;
    }

    interface CancelError extends Error {
        readonly name: 'CancelError';
    }
}

// Type definitions for p-cancelable 0.5
// Project: https://github.com/sindresorhus/p-cancelable#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

export = PCancelable;

declare const PCancelable: PCancelableConstructor;

interface PCancelableConstructor extends PromiseConstructor {
    readonly prototype: PCancelable.PCancelable<any>;
    readonly CancelError: PCancelable.CancelErrorConstructor;
    fn<T, R>(wrapper: (onCancel: (fn?: () => void) => void, input: T) => PromiseLike<R>): (input: T) => PCancelable.PCancelable<R>;
    new<T>(executor: (resolve: (value?: T | PromiseLike<T>) => void, reject: (reason?: any) => void, onCancel: (fn?: () => void) => void) => void): PCancelable.PCancelable<T>;
}

declare namespace PCancelable {
    interface PCancelable<T> extends Promise<T> {
        readonly isCanceled: boolean;
        cancel(reason?: string): void;

    }

    interface CancelErrorConstructor extends ErrorConstructor {
        new (reason?: string): CancelError;
    }

    interface CancelError extends Error {
        readonly name: 'CancelError';
        readonly isCanceled: boolean;
    }
}

Make p-cancellable types compatible with 0.5
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)