-
Notifications
You must be signed in to change notification settings - Fork 208
/
index.tests.ts
52 lines (44 loc) · 1.04 KB
/
index.tests.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
import compare from "./index";
type Type1 = {
a: number;
b: number;
};
type Type2 = {
c: number;
d: number;
e: number;
};
type Type3 = {
a: number;
b: number;
c: number;
};
const basicArr1 = [1, [2, 3]];
const basicArr2 = [1, [2, 3], 4];
const obj1: Type1 = { a: 2, b: 3 };
const obj2: Type2 = { c: 2, d: 3, e: 4 };
const obj3: Type3 = { a: 2, b: 3, c: 4 };
const funcA = () => true;
const funcB = () => (funcA() ? "yes" : undefined);
const funcC = () => (funcA() ? undefined : "yes");
const num1 = 1;
const num2 = new Number(1);
// OK
compare(1, 2);
compare("1", "2");
compare(false, true);
compare(BigInt(123), BigInt(456));
compare(basicArr1, basicArr1);
compare(basicArr1, basicArr2);
compare(obj1, obj1);
compare(obj1, obj3);
compare(obj3, obj1);
compare(funcB, funcC);
compare(obj1, { b: 3, a: 2 });
compare([1, [2, { a: 4 }], 4], [1, [2, { a: 4 }]]);
compare([1, [2, { a: 4 }], 4], [1, [2, { a: 4 }], 4]);
compare(NaN, NaN);
const compareIt = <T extends object>(a: T, b: T) => compare(a, b);
// Not okay
// @ts-expect-error
compare();