Skip to content

Commit 78f807c

Browse files
committed
Test that contextually typed generic this parameters are instantiated
1 parent ad56220 commit 78f807c

File tree

4 files changed

+127
-0
lines changed

4 files changed

+127
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// [instantiateContextuallyTypedGenericThis.ts]
2+
interface JQuery {
3+
each<T>(
4+
collection: T[], callback: (this: T, dit: T) => T
5+
): any;
6+
}
7+
8+
let $: JQuery;
9+
let lines: string[];
10+
$.each(lines, function(dit) {
11+
return dit.charAt(0) + this.charAt(1);
12+
});
13+
14+
15+
//// [instantiateContextuallyTypedGenericThis.js]
16+
var $;
17+
var lines;
18+
$.each(lines, function (dit) {
19+
return dit.charAt(0) + this.charAt(1);
20+
});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
=== tests/cases/compiler/instantiateContextuallyTypedGenericThis.ts ===
2+
interface JQuery {
3+
>JQuery : Symbol(JQuery, Decl(instantiateContextuallyTypedGenericThis.ts, 0, 0))
4+
5+
each<T>(
6+
>each : Symbol(JQuery.each, Decl(instantiateContextuallyTypedGenericThis.ts, 0, 18))
7+
>T : Symbol(T, Decl(instantiateContextuallyTypedGenericThis.ts, 1, 9))
8+
9+
collection: T[], callback: (this: T, dit: T) => T
10+
>collection : Symbol(collection, Decl(instantiateContextuallyTypedGenericThis.ts, 1, 12))
11+
>T : Symbol(T, Decl(instantiateContextuallyTypedGenericThis.ts, 1, 9))
12+
>callback : Symbol(callback, Decl(instantiateContextuallyTypedGenericThis.ts, 2, 24))
13+
>this : Symbol(this, Decl(instantiateContextuallyTypedGenericThis.ts, 2, 36))
14+
>T : Symbol(T, Decl(instantiateContextuallyTypedGenericThis.ts, 1, 9))
15+
>dit : Symbol(dit, Decl(instantiateContextuallyTypedGenericThis.ts, 2, 44))
16+
>T : Symbol(T, Decl(instantiateContextuallyTypedGenericThis.ts, 1, 9))
17+
>T : Symbol(T, Decl(instantiateContextuallyTypedGenericThis.ts, 1, 9))
18+
19+
): any;
20+
}
21+
22+
let $: JQuery;
23+
>$ : Symbol($, Decl(instantiateContextuallyTypedGenericThis.ts, 6, 3))
24+
>JQuery : Symbol(JQuery, Decl(instantiateContextuallyTypedGenericThis.ts, 0, 0))
25+
26+
let lines: string[];
27+
>lines : Symbol(lines, Decl(instantiateContextuallyTypedGenericThis.ts, 7, 3))
28+
29+
$.each(lines, function(dit) {
30+
>$.each : Symbol(JQuery.each, Decl(instantiateContextuallyTypedGenericThis.ts, 0, 18))
31+
>$ : Symbol($, Decl(instantiateContextuallyTypedGenericThis.ts, 6, 3))
32+
>each : Symbol(JQuery.each, Decl(instantiateContextuallyTypedGenericThis.ts, 0, 18))
33+
>lines : Symbol(lines, Decl(instantiateContextuallyTypedGenericThis.ts, 7, 3))
34+
>dit : Symbol(dit, Decl(instantiateContextuallyTypedGenericThis.ts, 8, 23))
35+
36+
return dit.charAt(0) + this.charAt(1);
37+
>dit.charAt : Symbol(String.charAt, Decl(lib.d.ts, --, --))
38+
>dit : Symbol(dit, Decl(instantiateContextuallyTypedGenericThis.ts, 8, 23))
39+
>charAt : Symbol(String.charAt, Decl(lib.d.ts, --, --))
40+
>this.charAt : Symbol(String.charAt, Decl(lib.d.ts, --, --))
41+
>charAt : Symbol(String.charAt, Decl(lib.d.ts, --, --))
42+
43+
});
44+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
=== tests/cases/compiler/instantiateContextuallyTypedGenericThis.ts ===
2+
interface JQuery {
3+
>JQuery : JQuery
4+
5+
each<T>(
6+
>each : <T>(collection: T[], callback: (this: T, dit: T) => T) => any
7+
>T : T
8+
9+
collection: T[], callback: (this: T, dit: T) => T
10+
>collection : T[]
11+
>T : T
12+
>callback : (this: T, dit: T) => T
13+
>this : T
14+
>T : T
15+
>dit : T
16+
>T : T
17+
>T : T
18+
19+
): any;
20+
}
21+
22+
let $: JQuery;
23+
>$ : JQuery
24+
>JQuery : JQuery
25+
26+
let lines: string[];
27+
>lines : string[]
28+
29+
$.each(lines, function(dit) {
30+
>$.each(lines, function(dit) { return dit.charAt(0) + this.charAt(1);}) : any
31+
>$.each : <T>(collection: T[], callback: (this: T, dit: T) => T) => any
32+
>$ : JQuery
33+
>each : <T>(collection: T[], callback: (this: T, dit: T) => T) => any
34+
>lines : string[]
35+
>function(dit) { return dit.charAt(0) + this.charAt(1);} : (dit: string) => string
36+
>dit : string
37+
38+
return dit.charAt(0) + this.charAt(1);
39+
>dit.charAt(0) + this.charAt(1) : string
40+
>dit.charAt(0) : string
41+
>dit.charAt : (pos: number) => string
42+
>dit : string
43+
>charAt : (pos: number) => string
44+
>0 : number
45+
>this.charAt(1) : string
46+
>this.charAt : (pos: number) => string
47+
>this : string
48+
>charAt : (pos: number) => string
49+
>1 : number
50+
51+
});
52+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
interface JQuery {
2+
each<T>(
3+
collection: T[], callback: (this: T, dit: T) => T
4+
): any;
5+
}
6+
7+
let $: JQuery;
8+
let lines: string[];
9+
$.each(lines, function(dit) {
10+
return dit.charAt(0) + this.charAt(1);
11+
});

0 commit comments

Comments
 (0)