Skip to content

Commit 70e8f73

Browse files
committed
Add tests
1 parent afc8a26 commit 70e8f73

File tree

7 files changed

+795
-0
lines changed

7 files changed

+795
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [strictFunctionTypes1.ts]
2+
declare function f1<T>(f1: (x: T) => void, f2: (x: T) => void): (x: T) => void;
3+
declare function f2<T>(obj: T, f1: (x: T) => void, f2: (x: T) => void): T;
4+
declare function f3<T>(obj: T, f1: (x: T) => void, f2: (f: (x: T) => void) => void): T;
5+
6+
interface Func<T> { (x: T): void }
7+
8+
declare function f4<T>(f1: Func<T>, f2: Func<T>): Func<T>;
9+
10+
declare function fo(x: Object): void;
11+
declare function fs(x: string): void;
12+
declare function fx(f: (x: "def") => void): void;
13+
14+
const x1 = f1(fo, fs); // (x: string) => void
15+
const x2 = f2("abc", fo, fs); // "abc"
16+
const x3 = f3("abc", fo, fx); // "abc" | "def"
17+
const x4 = f4(fo, fs); // Func<string>
18+
19+
20+
//// [strictFunctionTypes1.js]
21+
"use strict";
22+
var x1 = f1(fo, fs); // (x: string) => void
23+
var x2 = f2("abc", fo, fs); // "abc"
24+
var x3 = f3("abc", fo, fx); // "abc" | "def"
25+
var x4 = f4(fo, fs); // Func<string>
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
=== tests/cases/compiler/strictFunctionTypes1.ts ===
2+
declare function f1<T>(f1: (x: T) => void, f2: (x: T) => void): (x: T) => void;
3+
>f1 : Symbol(f1, Decl(strictFunctionTypes1.ts, 0, 0))
4+
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 0, 20))
5+
>f1 : Symbol(f1, Decl(strictFunctionTypes1.ts, 0, 23))
6+
>x : Symbol(x, Decl(strictFunctionTypes1.ts, 0, 28))
7+
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 0, 20))
8+
>f2 : Symbol(f2, Decl(strictFunctionTypes1.ts, 0, 42))
9+
>x : Symbol(x, Decl(strictFunctionTypes1.ts, 0, 48))
10+
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 0, 20))
11+
>x : Symbol(x, Decl(strictFunctionTypes1.ts, 0, 65))
12+
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 0, 20))
13+
14+
declare function f2<T>(obj: T, f1: (x: T) => void, f2: (x: T) => void): T;
15+
>f2 : Symbol(f2, Decl(strictFunctionTypes1.ts, 0, 79))
16+
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 1, 20))
17+
>obj : Symbol(obj, Decl(strictFunctionTypes1.ts, 1, 23))
18+
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 1, 20))
19+
>f1 : Symbol(f1, Decl(strictFunctionTypes1.ts, 1, 30))
20+
>x : Symbol(x, Decl(strictFunctionTypes1.ts, 1, 36))
21+
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 1, 20))
22+
>f2 : Symbol(f2, Decl(strictFunctionTypes1.ts, 1, 50))
23+
>x : Symbol(x, Decl(strictFunctionTypes1.ts, 1, 56))
24+
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 1, 20))
25+
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 1, 20))
26+
27+
declare function f3<T>(obj: T, f1: (x: T) => void, f2: (f: (x: T) => void) => void): T;
28+
>f3 : Symbol(f3, Decl(strictFunctionTypes1.ts, 1, 74))
29+
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 2, 20))
30+
>obj : Symbol(obj, Decl(strictFunctionTypes1.ts, 2, 23))
31+
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 2, 20))
32+
>f1 : Symbol(f1, Decl(strictFunctionTypes1.ts, 2, 30))
33+
>x : Symbol(x, Decl(strictFunctionTypes1.ts, 2, 36))
34+
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 2, 20))
35+
>f2 : Symbol(f2, Decl(strictFunctionTypes1.ts, 2, 50))
36+
>f : Symbol(f, Decl(strictFunctionTypes1.ts, 2, 56))
37+
>x : Symbol(x, Decl(strictFunctionTypes1.ts, 2, 60))
38+
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 2, 20))
39+
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 2, 20))
40+
41+
interface Func<T> { (x: T): void }
42+
>Func : Symbol(Func, Decl(strictFunctionTypes1.ts, 2, 87))
43+
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 4, 15))
44+
>x : Symbol(x, Decl(strictFunctionTypes1.ts, 4, 21))
45+
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 4, 15))
46+
47+
declare function f4<T>(f1: Func<T>, f2: Func<T>): Func<T>;
48+
>f4 : Symbol(f4, Decl(strictFunctionTypes1.ts, 4, 34))
49+
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 6, 20))
50+
>f1 : Symbol(f1, Decl(strictFunctionTypes1.ts, 6, 23))
51+
>Func : Symbol(Func, Decl(strictFunctionTypes1.ts, 2, 87))
52+
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 6, 20))
53+
>f2 : Symbol(f2, Decl(strictFunctionTypes1.ts, 6, 35))
54+
>Func : Symbol(Func, Decl(strictFunctionTypes1.ts, 2, 87))
55+
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 6, 20))
56+
>Func : Symbol(Func, Decl(strictFunctionTypes1.ts, 2, 87))
57+
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 6, 20))
58+
59+
declare function fo(x: Object): void;
60+
>fo : Symbol(fo, Decl(strictFunctionTypes1.ts, 6, 58))
61+
>x : Symbol(x, Decl(strictFunctionTypes1.ts, 8, 20))
62+
>Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
63+
64+
declare function fs(x: string): void;
65+
>fs : Symbol(fs, Decl(strictFunctionTypes1.ts, 8, 37))
66+
>x : Symbol(x, Decl(strictFunctionTypes1.ts, 9, 20))
67+
68+
declare function fx(f: (x: "def") => void): void;
69+
>fx : Symbol(fx, Decl(strictFunctionTypes1.ts, 9, 37))
70+
>f : Symbol(f, Decl(strictFunctionTypes1.ts, 10, 20))
71+
>x : Symbol(x, Decl(strictFunctionTypes1.ts, 10, 24))
72+
73+
const x1 = f1(fo, fs); // (x: string) => void
74+
>x1 : Symbol(x1, Decl(strictFunctionTypes1.ts, 12, 5))
75+
>f1 : Symbol(f1, Decl(strictFunctionTypes1.ts, 0, 0))
76+
>fo : Symbol(fo, Decl(strictFunctionTypes1.ts, 6, 58))
77+
>fs : Symbol(fs, Decl(strictFunctionTypes1.ts, 8, 37))
78+
79+
const x2 = f2("abc", fo, fs); // "abc"
80+
>x2 : Symbol(x2, Decl(strictFunctionTypes1.ts, 13, 5))
81+
>f2 : Symbol(f2, Decl(strictFunctionTypes1.ts, 0, 79))
82+
>fo : Symbol(fo, Decl(strictFunctionTypes1.ts, 6, 58))
83+
>fs : Symbol(fs, Decl(strictFunctionTypes1.ts, 8, 37))
84+
85+
const x3 = f3("abc", fo, fx); // "abc" | "def"
86+
>x3 : Symbol(x3, Decl(strictFunctionTypes1.ts, 14, 5))
87+
>f3 : Symbol(f3, Decl(strictFunctionTypes1.ts, 1, 74))
88+
>fo : Symbol(fo, Decl(strictFunctionTypes1.ts, 6, 58))
89+
>fx : Symbol(fx, Decl(strictFunctionTypes1.ts, 9, 37))
90+
91+
const x4 = f4(fo, fs); // Func<string>
92+
>x4 : Symbol(x4, Decl(strictFunctionTypes1.ts, 15, 5))
93+
>f4 : Symbol(f4, Decl(strictFunctionTypes1.ts, 4, 34))
94+
>fo : Symbol(fo, Decl(strictFunctionTypes1.ts, 6, 58))
95+
>fs : Symbol(fs, Decl(strictFunctionTypes1.ts, 8, 37))
96+
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
=== tests/cases/compiler/strictFunctionTypes1.ts ===
2+
declare function f1<T>(f1: (x: T) => void, f2: (x: T) => void): (x: T) => void;
3+
>f1 : <T>(f1: (x: T) => void, f2: (x: T) => void) => (x: T) => void
4+
>T : T
5+
>f1 : (x: T) => void
6+
>x : T
7+
>T : T
8+
>f2 : (x: T) => void
9+
>x : T
10+
>T : T
11+
>x : T
12+
>T : T
13+
14+
declare function f2<T>(obj: T, f1: (x: T) => void, f2: (x: T) => void): T;
15+
>f2 : <T>(obj: T, f1: (x: T) => void, f2: (x: T) => void) => T
16+
>T : T
17+
>obj : T
18+
>T : T
19+
>f1 : (x: T) => void
20+
>x : T
21+
>T : T
22+
>f2 : (x: T) => void
23+
>x : T
24+
>T : T
25+
>T : T
26+
27+
declare function f3<T>(obj: T, f1: (x: T) => void, f2: (f: (x: T) => void) => void): T;
28+
>f3 : <T>(obj: T, f1: (x: T) => void, f2: (f: (x: T) => void) => void) => T
29+
>T : T
30+
>obj : T
31+
>T : T
32+
>f1 : (x: T) => void
33+
>x : T
34+
>T : T
35+
>f2 : (f: (x: T) => void) => void
36+
>f : (x: T) => void
37+
>x : T
38+
>T : T
39+
>T : T
40+
41+
interface Func<T> { (x: T): void }
42+
>Func : Func<T>
43+
>T : T
44+
>x : T
45+
>T : T
46+
47+
declare function f4<T>(f1: Func<T>, f2: Func<T>): Func<T>;
48+
>f4 : <T>(f1: Func<T>, f2: Func<T>) => Func<T>
49+
>T : T
50+
>f1 : Func<T>
51+
>Func : Func<T>
52+
>T : T
53+
>f2 : Func<T>
54+
>Func : Func<T>
55+
>T : T
56+
>Func : Func<T>
57+
>T : T
58+
59+
declare function fo(x: Object): void;
60+
>fo : (x: Object) => void
61+
>x : Object
62+
>Object : Object
63+
64+
declare function fs(x: string): void;
65+
>fs : (x: string) => void
66+
>x : string
67+
68+
declare function fx(f: (x: "def") => void): void;
69+
>fx : (f: (x: "def") => void) => void
70+
>f : (x: "def") => void
71+
>x : "def"
72+
73+
const x1 = f1(fo, fs); // (x: string) => void
74+
>x1 : (x: string) => void
75+
>f1(fo, fs) : (x: string) => void
76+
>f1 : <T>(f1: (x: T) => void, f2: (x: T) => void) => (x: T) => void
77+
>fo : (x: Object) => void
78+
>fs : (x: string) => void
79+
80+
const x2 = f2("abc", fo, fs); // "abc"
81+
>x2 : "abc"
82+
>f2("abc", fo, fs) : "abc"
83+
>f2 : <T>(obj: T, f1: (x: T) => void, f2: (x: T) => void) => T
84+
>"abc" : "abc"
85+
>fo : (x: Object) => void
86+
>fs : (x: string) => void
87+
88+
const x3 = f3("abc", fo, fx); // "abc" | "def"
89+
>x3 : "def" | "abc"
90+
>f3("abc", fo, fx) : "def" | "abc"
91+
>f3 : <T>(obj: T, f1: (x: T) => void, f2: (f: (x: T) => void) => void) => T
92+
>"abc" : "abc"
93+
>fo : (x: Object) => void
94+
>fx : (f: (x: "def") => void) => void
95+
96+
const x4 = f4(fo, fs); // Func<string>
97+
>x4 : Func<string>
98+
>f4(fo, fs) : Func<string>
99+
>f4 : <T>(f1: Func<T>, f2: Func<T>) => Func<T>
100+
>fo : (x: Object) => void
101+
>fs : (x: string) => void
102+

0 commit comments

Comments
 (0)