mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 01:49:57 -05:00
Test that contextually typed generic this parameters are instantiated
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
//// [instantiateContextuallyTypedGenericThis.ts]
|
||||
interface JQuery {
|
||||
each<T>(
|
||||
collection: T[], callback: (this: T, dit: T) => T
|
||||
): any;
|
||||
}
|
||||
|
||||
let $: JQuery;
|
||||
let lines: string[];
|
||||
$.each(lines, function(dit) {
|
||||
return dit.charAt(0) + this.charAt(1);
|
||||
});
|
||||
|
||||
|
||||
//// [instantiateContextuallyTypedGenericThis.js]
|
||||
var $;
|
||||
var lines;
|
||||
$.each(lines, function (dit) {
|
||||
return dit.charAt(0) + this.charAt(1);
|
||||
});
|
||||
@@ -0,0 +1,44 @@
|
||||
=== tests/cases/compiler/instantiateContextuallyTypedGenericThis.ts ===
|
||||
interface JQuery {
|
||||
>JQuery : Symbol(JQuery, Decl(instantiateContextuallyTypedGenericThis.ts, 0, 0))
|
||||
|
||||
each<T>(
|
||||
>each : Symbol(JQuery.each, Decl(instantiateContextuallyTypedGenericThis.ts, 0, 18))
|
||||
>T : Symbol(T, Decl(instantiateContextuallyTypedGenericThis.ts, 1, 9))
|
||||
|
||||
collection: T[], callback: (this: T, dit: T) => T
|
||||
>collection : Symbol(collection, Decl(instantiateContextuallyTypedGenericThis.ts, 1, 12))
|
||||
>T : Symbol(T, Decl(instantiateContextuallyTypedGenericThis.ts, 1, 9))
|
||||
>callback : Symbol(callback, Decl(instantiateContextuallyTypedGenericThis.ts, 2, 24))
|
||||
>this : Symbol(this, Decl(instantiateContextuallyTypedGenericThis.ts, 2, 36))
|
||||
>T : Symbol(T, Decl(instantiateContextuallyTypedGenericThis.ts, 1, 9))
|
||||
>dit : Symbol(dit, Decl(instantiateContextuallyTypedGenericThis.ts, 2, 44))
|
||||
>T : Symbol(T, Decl(instantiateContextuallyTypedGenericThis.ts, 1, 9))
|
||||
>T : Symbol(T, Decl(instantiateContextuallyTypedGenericThis.ts, 1, 9))
|
||||
|
||||
): any;
|
||||
}
|
||||
|
||||
let $: JQuery;
|
||||
>$ : Symbol($, Decl(instantiateContextuallyTypedGenericThis.ts, 6, 3))
|
||||
>JQuery : Symbol(JQuery, Decl(instantiateContextuallyTypedGenericThis.ts, 0, 0))
|
||||
|
||||
let lines: string[];
|
||||
>lines : Symbol(lines, Decl(instantiateContextuallyTypedGenericThis.ts, 7, 3))
|
||||
|
||||
$.each(lines, function(dit) {
|
||||
>$.each : Symbol(JQuery.each, Decl(instantiateContextuallyTypedGenericThis.ts, 0, 18))
|
||||
>$ : Symbol($, Decl(instantiateContextuallyTypedGenericThis.ts, 6, 3))
|
||||
>each : Symbol(JQuery.each, Decl(instantiateContextuallyTypedGenericThis.ts, 0, 18))
|
||||
>lines : Symbol(lines, Decl(instantiateContextuallyTypedGenericThis.ts, 7, 3))
|
||||
>dit : Symbol(dit, Decl(instantiateContextuallyTypedGenericThis.ts, 8, 23))
|
||||
|
||||
return dit.charAt(0) + this.charAt(1);
|
||||
>dit.charAt : Symbol(String.charAt, Decl(lib.d.ts, --, --))
|
||||
>dit : Symbol(dit, Decl(instantiateContextuallyTypedGenericThis.ts, 8, 23))
|
||||
>charAt : Symbol(String.charAt, Decl(lib.d.ts, --, --))
|
||||
>this.charAt : Symbol(String.charAt, Decl(lib.d.ts, --, --))
|
||||
>charAt : Symbol(String.charAt, Decl(lib.d.ts, --, --))
|
||||
|
||||
});
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
=== tests/cases/compiler/instantiateContextuallyTypedGenericThis.ts ===
|
||||
interface JQuery {
|
||||
>JQuery : JQuery
|
||||
|
||||
each<T>(
|
||||
>each : <T>(collection: T[], callback: (this: T, dit: T) => T) => any
|
||||
>T : T
|
||||
|
||||
collection: T[], callback: (this: T, dit: T) => T
|
||||
>collection : T[]
|
||||
>T : T
|
||||
>callback : (this: T, dit: T) => T
|
||||
>this : T
|
||||
>T : T
|
||||
>dit : T
|
||||
>T : T
|
||||
>T : T
|
||||
|
||||
): any;
|
||||
}
|
||||
|
||||
let $: JQuery;
|
||||
>$ : JQuery
|
||||
>JQuery : JQuery
|
||||
|
||||
let lines: string[];
|
||||
>lines : string[]
|
||||
|
||||
$.each(lines, function(dit) {
|
||||
>$.each(lines, function(dit) { return dit.charAt(0) + this.charAt(1);}) : any
|
||||
>$.each : <T>(collection: T[], callback: (this: T, dit: T) => T) => any
|
||||
>$ : JQuery
|
||||
>each : <T>(collection: T[], callback: (this: T, dit: T) => T) => any
|
||||
>lines : string[]
|
||||
>function(dit) { return dit.charAt(0) + this.charAt(1);} : (dit: string) => string
|
||||
>dit : string
|
||||
|
||||
return dit.charAt(0) + this.charAt(1);
|
||||
>dit.charAt(0) + this.charAt(1) : string
|
||||
>dit.charAt(0) : string
|
||||
>dit.charAt : (pos: number) => string
|
||||
>dit : string
|
||||
>charAt : (pos: number) => string
|
||||
>0 : number
|
||||
>this.charAt(1) : string
|
||||
>this.charAt : (pos: number) => string
|
||||
>this : string
|
||||
>charAt : (pos: number) => string
|
||||
>1 : number
|
||||
|
||||
});
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
interface JQuery {
|
||||
each<T>(
|
||||
collection: T[], callback: (this: T, dit: T) => T
|
||||
): any;
|
||||
}
|
||||
|
||||
let $: JQuery;
|
||||
let lines: string[];
|
||||
$.each(lines, function(dit) {
|
||||
return dit.charAt(0) + this.charAt(1);
|
||||
});
|
||||
Reference in New Issue
Block a user