Skip to content

Commit 22c934a

Browse files
committed
Add tests
1 parent 549c684 commit 22c934a

File tree

1 file changed

+120
-15
lines changed

1 file changed

+120
-15
lines changed

tests/cases/compiler/genericFunctionInference1.ts

Lines changed: 120 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,129 @@ declare function pipe<A extends any[], B, C, D>(ab: (...args: A) => B, bc: (b: B
77

88
declare function list<T>(a: T): T[];
99
declare function box<V>(x: V): { value: V };
10+
declare function foo<T extends { value: T }>(x: T): T;
1011

1112
const f00 = pipe(list);
1213
const f01 = pipe(list, box);
13-
const f02 = pipe(x => list(x), box);
14-
const f03 = pipe(list, x => box(x));
15-
const f04 = pipe(x => list(x), x => box(x))
16-
const f05 = pipe(list, pipe(box));
17-
const f06 = pipe(x => list(x), pipe(box));
18-
const f07 = pipe(x => list(x), pipe(x => box(x)));
19-
20-
const f10: <T>(x: T) => T[] = pipe(list);
21-
const f11: <T>(x: T) => { value: T[] } = pipe(list, box);
22-
const f12: <T>(x: T) => { value: T[] } = pipe(x => list(x), box);
23-
const f13: <T>(x: T) => { value: T[] } = pipe(list, x => box(x));
24-
const f14: <T>(x: T) => { value: T[] } = pipe(x => list(x), x => box(x))
25-
const f15: <T>(x: T) => { value: T[] } = pipe(list, pipe(box));
26-
const f16: <T>(x: T) => { value: T[] } = pipe(x => list(x), pipe(box));
27-
const f17: <T>(x: T) => { value: T[] } = pipe(x => list(x), pipe(x => box(x)));
14+
const f02 = pipe(box, list);
15+
const f03 = pipe(x => list(x), box);
16+
const f04 = pipe(list, x => box(x));
17+
const f05 = pipe(x => list(x), x => box(x))
18+
const f06 = pipe(list, pipe(box));
19+
const f07 = pipe(x => list(x), pipe(box));
20+
const f08 = pipe(x => list(x), pipe(x => box(x)));
21+
const f09 = pipe(list, x => x.length);
22+
const f10 = pipe(foo);
23+
const f11 = pipe(foo, foo);
24+
25+
const g00: <T>(x: T) => T[] = pipe(list);
26+
const g01: <T>(x: T) => { value: T[] } = pipe(list, box);
27+
const g02: <T>(x: T) => { value: T }[] = pipe(box, list);
28+
const g03: <T>(x: T) => { value: T[] } = pipe(x => list(x), box);
29+
const g04: <T>(x: T) => { value: T[] } = pipe(list, x => box(x));
30+
const g05: <T>(x: T) => { value: T[] } = pipe(x => list(x), x => box(x))
31+
const g06: <T>(x: T) => { value: T[] } = pipe(list, pipe(box));
32+
const g07: <T>(x: T) => { value: T[] } = pipe(x => list(x), pipe(box));
33+
const g08: <T>(x: T) => { value: T[] } = pipe(x => list(x), pipe(x => box(x)));
34+
const g09: <T>(x: T) => number = pipe(list, x => x.length);
35+
const g10: <T extends { value: T }>(x: T) => T = pipe(foo);
36+
const g12: <T extends { value: T }>(x: T) => T = pipe(foo, foo);
37+
38+
declare function pipe2<A, B, C, D>(ab: (a: A) => B, cd: (c: C) => D): (a: [A, C]) => [B, D];
39+
40+
const f20 = pipe2(list, box);
41+
const f21 = pipe2(box, list);
42+
const f22 = pipe2(list, list);
43+
const f23 = pipe2(box, box);
44+
const f24 = pipe2(f20, f20);
45+
const f25 = pipe2(foo, foo);
46+
const f26 = pipe2(f25, f25);
47+
48+
declare function pipe3<A, B, C>(ab: (a: A) => B, ac: (a: A) => C): (a: A) => [B, C];
49+
50+
const f30 = pipe3(list, box);
51+
const f31 = pipe3(box, list);
52+
const f32 = pipe3(list, list);
53+
54+
declare function pipe4<A, B, C>(funcs: [(a: A) => B, (b: B) => C]): (a: A) => C;
55+
56+
const f40 = pipe4([list, box]);
57+
const f41 = pipe4([box, list]);
58+
59+
declare function pipe5<A, B>(f: (a: A) => B): { f: (a: A) => B };
60+
61+
const f50 = pipe5(list); // No higher order inference
62+
63+
// #417
64+
65+
function mirror<A, B>(f: (a: A) => B): (a: A) => B { return f; }
66+
var identityM = mirror(identity);
67+
68+
var x = 1;
69+
var y = identity(x);
70+
var z = identityM(x);
71+
72+
// #3038
73+
74+
export function keyOf<a>(value: { key: a; }): a {
75+
return value.key;
76+
}
77+
export interface Data {
78+
key: number;
79+
value: Date;
80+
}
81+
82+
var data: Data[] = [];
83+
84+
declare function toKeys<a>(values: a[], toKey: (value: a) => string): string[];
85+
86+
toKeys(data, keyOf); // Error
87+
88+
// #9366
89+
90+
function flip<a, b, c>(f: (a: a, b: b) => c): (b: b, a: a) => c {
91+
return (b: b, a: a) => f(a, b);
92+
}
93+
function zip<T, U>(x: T, y: U): [T, U] {
94+
return [x, y];
95+
}
96+
97+
var expected: <T, U>(y: U, x: T) => [T, U] = flip(zip);
98+
var actual = flip(zip);
99+
100+
// #9366
101+
102+
const map = <T, U>(transform: (t: T) => U) =>
103+
(arr: T[]) => arr.map(transform)
104+
105+
const identityStr = (t: string) => t;
106+
107+
const arr: string[] = map(identityStr)(['a']);
108+
const arr1: string[] = map(identity)(['a']);
109+
110+
// #9949
111+
112+
function of2<a, b>(one: a, two: b): [a, b] {
113+
return [one, two];
114+
}
115+
116+
const flipped = flip(of2);
117+
118+
// #29904.1
119+
120+
type Component<P> = (props: P) => {};
121+
122+
declare const myHoc1: <P>(C: Component<P>) => Component<P>;
123+
declare const myHoc2: <P>(C: Component<P>) => Component<P>;
124+
125+
declare const MyComponent1: Component<{ foo: 1 }>;
126+
127+
const enhance = pipe(
128+
myHoc1,
129+
myHoc2,
130+
);
131+
132+
const MyComponent2 = enhance(MyComponent1);
28133

29134
// #29904.2
30135

0 commit comments

Comments
 (0)