Skip to content

Commit 414f165

Browse files
committed
Add tests
1 parent a87baa2 commit 414f165

File tree

4 files changed

+202
-0
lines changed

4 files changed

+202
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//// [genericFunctionParameters.ts]
2+
declare function f1<T>(cb: <S>(x: S) => T): T;
3+
declare function f2<T>(cb: <S extends number>(x: S) => T): T;
4+
declare function f3<T>(cb: <S extends Array<S>>(x: S) => T): T;
5+
6+
let x1 = f1(x => x); // {}
7+
let x2 = f2(x => x); // number
8+
let x3 = f3(x => x); // Array<any>
9+
10+
// Repro from #19345
11+
12+
declare const s: <R>(go: <S>(ops: { init(): S; }) => R) => R;
13+
const x = s(a => a.init()); // x is any, should have been {}
14+
15+
16+
//// [genericFunctionParameters.js]
17+
"use strict";
18+
var x1 = f1(function (x) { return x; }); // {}
19+
var x2 = f2(function (x) { return x; }); // number
20+
var x3 = f3(function (x) { return x; }); // Array<any>
21+
var x = s(function (a) { return a.init(); }); // x is any, should have been {}
22+
23+
24+
//// [genericFunctionParameters.d.ts]
25+
declare function f1<T>(cb: <S>(x: S) => T): T;
26+
declare function f2<T>(cb: <S extends number>(x: S) => T): T;
27+
declare function f3<T>(cb: <S extends Array<S>>(x: S) => T): T;
28+
declare let x1: {};
29+
declare let x2: number;
30+
declare let x3: any[];
31+
declare const s: <R>(go: <S>(ops: {
32+
init(): S;
33+
}) => R) => R;
34+
declare const x: {};
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
=== tests/cases/conformance/types/typeRelationships/typeInference/genericFunctionParameters.ts ===
2+
declare function f1<T>(cb: <S>(x: S) => T): T;
3+
>f1 : Symbol(f1, Decl(genericFunctionParameters.ts, 0, 0))
4+
>T : Symbol(T, Decl(genericFunctionParameters.ts, 0, 20))
5+
>cb : Symbol(cb, Decl(genericFunctionParameters.ts, 0, 23))
6+
>S : Symbol(S, Decl(genericFunctionParameters.ts, 0, 28))
7+
>x : Symbol(x, Decl(genericFunctionParameters.ts, 0, 31))
8+
>S : Symbol(S, Decl(genericFunctionParameters.ts, 0, 28))
9+
>T : Symbol(T, Decl(genericFunctionParameters.ts, 0, 20))
10+
>T : Symbol(T, Decl(genericFunctionParameters.ts, 0, 20))
11+
12+
declare function f2<T>(cb: <S extends number>(x: S) => T): T;
13+
>f2 : Symbol(f2, Decl(genericFunctionParameters.ts, 0, 46))
14+
>T : Symbol(T, Decl(genericFunctionParameters.ts, 1, 20))
15+
>cb : Symbol(cb, Decl(genericFunctionParameters.ts, 1, 23))
16+
>S : Symbol(S, Decl(genericFunctionParameters.ts, 1, 28))
17+
>x : Symbol(x, Decl(genericFunctionParameters.ts, 1, 46))
18+
>S : Symbol(S, Decl(genericFunctionParameters.ts, 1, 28))
19+
>T : Symbol(T, Decl(genericFunctionParameters.ts, 1, 20))
20+
>T : Symbol(T, Decl(genericFunctionParameters.ts, 1, 20))
21+
22+
declare function f3<T>(cb: <S extends Array<S>>(x: S) => T): T;
23+
>f3 : Symbol(f3, Decl(genericFunctionParameters.ts, 1, 61))
24+
>T : Symbol(T, Decl(genericFunctionParameters.ts, 2, 20))
25+
>cb : Symbol(cb, Decl(genericFunctionParameters.ts, 2, 23))
26+
>S : Symbol(S, Decl(genericFunctionParameters.ts, 2, 28))
27+
>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
28+
>S : Symbol(S, Decl(genericFunctionParameters.ts, 2, 28))
29+
>x : Symbol(x, Decl(genericFunctionParameters.ts, 2, 48))
30+
>S : Symbol(S, Decl(genericFunctionParameters.ts, 2, 28))
31+
>T : Symbol(T, Decl(genericFunctionParameters.ts, 2, 20))
32+
>T : Symbol(T, Decl(genericFunctionParameters.ts, 2, 20))
33+
34+
let x1 = f1(x => x); // {}
35+
>x1 : Symbol(x1, Decl(genericFunctionParameters.ts, 4, 3))
36+
>f1 : Symbol(f1, Decl(genericFunctionParameters.ts, 0, 0))
37+
>x : Symbol(x, Decl(genericFunctionParameters.ts, 4, 12))
38+
>x : Symbol(x, Decl(genericFunctionParameters.ts, 4, 12))
39+
40+
let x2 = f2(x => x); // number
41+
>x2 : Symbol(x2, Decl(genericFunctionParameters.ts, 5, 3))
42+
>f2 : Symbol(f2, Decl(genericFunctionParameters.ts, 0, 46))
43+
>x : Symbol(x, Decl(genericFunctionParameters.ts, 5, 12))
44+
>x : Symbol(x, Decl(genericFunctionParameters.ts, 5, 12))
45+
46+
let x3 = f3(x => x); // Array<any>
47+
>x3 : Symbol(x3, Decl(genericFunctionParameters.ts, 6, 3))
48+
>f3 : Symbol(f3, Decl(genericFunctionParameters.ts, 1, 61))
49+
>x : Symbol(x, Decl(genericFunctionParameters.ts, 6, 12))
50+
>x : Symbol(x, Decl(genericFunctionParameters.ts, 6, 12))
51+
52+
// Repro from #19345
53+
54+
declare const s: <R>(go: <S>(ops: { init(): S; }) => R) => R;
55+
>s : Symbol(s, Decl(genericFunctionParameters.ts, 10, 13))
56+
>R : Symbol(R, Decl(genericFunctionParameters.ts, 10, 18))
57+
>go : Symbol(go, Decl(genericFunctionParameters.ts, 10, 21))
58+
>S : Symbol(S, Decl(genericFunctionParameters.ts, 10, 26))
59+
>ops : Symbol(ops, Decl(genericFunctionParameters.ts, 10, 29))
60+
>init : Symbol(init, Decl(genericFunctionParameters.ts, 10, 35))
61+
>S : Symbol(S, Decl(genericFunctionParameters.ts, 10, 26))
62+
>R : Symbol(R, Decl(genericFunctionParameters.ts, 10, 18))
63+
>R : Symbol(R, Decl(genericFunctionParameters.ts, 10, 18))
64+
65+
const x = s(a => a.init()); // x is any, should have been {}
66+
>x : Symbol(x, Decl(genericFunctionParameters.ts, 11, 5))
67+
>s : Symbol(s, Decl(genericFunctionParameters.ts, 10, 13))
68+
>a : Symbol(a, Decl(genericFunctionParameters.ts, 11, 12))
69+
>a.init : Symbol(init, Decl(genericFunctionParameters.ts, 10, 35))
70+
>a : Symbol(a, Decl(genericFunctionParameters.ts, 11, 12))
71+
>init : Symbol(init, Decl(genericFunctionParameters.ts, 10, 35))
72+
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
=== tests/cases/conformance/types/typeRelationships/typeInference/genericFunctionParameters.ts ===
2+
declare function f1<T>(cb: <S>(x: S) => T): T;
3+
>f1 : <T>(cb: <S>(x: S) => T) => T
4+
>T : T
5+
>cb : <S>(x: S) => T
6+
>S : S
7+
>x : S
8+
>S : S
9+
>T : T
10+
>T : T
11+
12+
declare function f2<T>(cb: <S extends number>(x: S) => T): T;
13+
>f2 : <T>(cb: <S extends number>(x: S) => T) => T
14+
>T : T
15+
>cb : <S extends number>(x: S) => T
16+
>S : S
17+
>x : S
18+
>S : S
19+
>T : T
20+
>T : T
21+
22+
declare function f3<T>(cb: <S extends Array<S>>(x: S) => T): T;
23+
>f3 : <T>(cb: <S extends S[]>(x: S) => T) => T
24+
>T : T
25+
>cb : <S extends S[]>(x: S) => T
26+
>S : S
27+
>Array : T[]
28+
>S : S
29+
>x : S
30+
>S : S
31+
>T : T
32+
>T : T
33+
34+
let x1 = f1(x => x); // {}
35+
>x1 : {}
36+
>f1(x => x) : {}
37+
>f1 : <T>(cb: <S>(x: S) => T) => T
38+
>x => x : <S>(x: S) => S
39+
>x : S
40+
>x : S
41+
42+
let x2 = f2(x => x); // number
43+
>x2 : number
44+
>f2(x => x) : number
45+
>f2 : <T>(cb: <S extends number>(x: S) => T) => T
46+
>x => x : <S extends number>(x: S) => S
47+
>x : S
48+
>x : S
49+
50+
let x3 = f3(x => x); // Array<any>
51+
>x3 : any[]
52+
>f3(x => x) : any[]
53+
>f3 : <T>(cb: <S extends S[]>(x: S) => T) => T
54+
>x => x : <S extends S[]>(x: S) => S
55+
>x : S
56+
>x : S
57+
58+
// Repro from #19345
59+
60+
declare const s: <R>(go: <S>(ops: { init(): S; }) => R) => R;
61+
>s : <R>(go: <S>(ops: { init(): S; }) => R) => R
62+
>R : R
63+
>go : <S>(ops: { init(): S; }) => R
64+
>S : S
65+
>ops : { init(): S; }
66+
>init : () => S
67+
>S : S
68+
>R : R
69+
>R : R
70+
71+
const x = s(a => a.init()); // x is any, should have been {}
72+
>x : {}
73+
>s(a => a.init()) : {}
74+
>s : <R>(go: <S>(ops: { init(): S; }) => R) => R
75+
>a => a.init() : <S>(a: { init(): S; }) => S
76+
>a : { init(): S; }
77+
>a.init() : S
78+
>a.init : () => S
79+
>a : { init(): S; }
80+
>init : () => S
81+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @strict: true
2+
// @declaration: true
3+
4+
declare function f1<T>(cb: <S>(x: S) => T): T;
5+
declare function f2<T>(cb: <S extends number>(x: S) => T): T;
6+
declare function f3<T>(cb: <S extends Array<S>>(x: S) => T): T;
7+
8+
let x1 = f1(x => x); // {}
9+
let x2 = f2(x => x); // number
10+
let x3 = f3(x => x); // Array<any>
11+
12+
// Repro from #19345
13+
14+
declare const s: <R>(go: <S>(ops: { init(): S; }) => R) => R;
15+
const x = s(a => a.init()); // x is any, should have been {}

0 commit comments

Comments
 (0)