-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
index.test-d.ts
100 lines (87 loc) · 2.26 KB
/
index.test-d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import {expectType} from 'tsd';
import PCancelable, {OnCancelFunction, CancelError} from './index.js';
const cancelablePromise: PCancelable<number> = new PCancelable(
(resolve, reject, onCancel) => {
resolve(1);
resolve(Promise.resolve(1));
reject();
reject('foo');
expectType<OnCancelFunction>(onCancel);
onCancel(() => 'foo');
onCancel.shouldReject = false;
},
);
cancelablePromise.cancel();
cancelablePromise.cancel('foo');
expectType<boolean>(cancelablePromise.isCanceled);
const function0 = PCancelable.fn(async onCancel => {
expectType<OnCancelFunction>(onCancel);
return 10;
});
expectType<() => PCancelable<number>>(function0);
const function1 = PCancelable.fn(
async (_parameter1: string, _onCancel: OnCancelFunction) => 10,
);
expectType<(parameter1: string) => PCancelable<number>>(function1);
const function2 = PCancelable.fn(
async (_parameter1: string, _parameter2: boolean, _onCancel: OnCancelFunction) => 10,
);
expectType<(_parameter1: string, _parameter2: boolean) => PCancelable<number>>(
function2,
);
const function3 = PCancelable.fn(
async (
_parameter1: string,
_parameter2: boolean,
_parameter3: number,
_onCancel: OnCancelFunction,
) => 10,
);
expectType<
(
parameter1: string,
parameter2: boolean,
parameter3: number
) => PCancelable<number>
>(function3);
const function4 = PCancelable.fn(
async (
_parameter1: string,
_parameter2: boolean,
_parameter3: number,
_parameter4: symbol,
_onCancel: OnCancelFunction,
) => 10,
);
expectType<
(
parameter1: string,
parameter2: boolean,
parameter3: number,
parameter4: symbol
) => PCancelable<number>
>(function4);
const function5 = PCancelable.fn(
async (
_parameter1: string,
_parameter2: boolean,
_parameter3: number,
_parameter4: symbol,
_parameter5: null, // eslint-disable-line @typescript-eslint/ban-types
_onCancel: OnCancelFunction,
) => 10,
);
expectType<
(
parameter1: string,
parameter2: boolean,
parameter3: number,
parameter4: symbol,
parameter5: null // eslint-disable-line @typescript-eslint/ban-types
) => PCancelable<number>
>(function5);
const cancelError = new CancelError();
new CancelError('foo'); // eslint-disable-line no-new
expectType<CancelError>(cancelError);
expectType<'CancelError'>(cancelError.name);
expectType<true>(cancelError.isCanceled);