138 lines
2.8 KiB
Text
138 lines
2.8 KiB
Text
=== tests/cases/conformance/types/typeParameters/typeParameterLists/propertyAccessOnTypeParameterWithConstraints.ts ===
|
|
// generic types should behave as if they have properties of their constraint type
|
|
// no errors expected
|
|
|
|
class C<T extends Date> {
|
|
>C : C<T>
|
|
>T : T
|
|
>Date : Date
|
|
|
|
f() {
|
|
>f : () => number
|
|
|
|
var x: T;
|
|
>x : T
|
|
>T : T
|
|
|
|
var a = x['getDate'](); // number
|
|
>a : number
|
|
>x['getDate']() : number
|
|
>x['getDate'] : () => number
|
|
>x : T
|
|
>'getDate' : string
|
|
|
|
return a + x.getDate();
|
|
>a + x.getDate() : number
|
|
>a : number
|
|
>x.getDate() : number
|
|
>x.getDate : () => number
|
|
>x : T
|
|
>getDate : () => number
|
|
}
|
|
}
|
|
|
|
var r = (new C<Date>()).f();
|
|
>r : number
|
|
>(new C<Date>()).f() : number
|
|
>(new C<Date>()).f : () => number
|
|
>(new C<Date>()) : C<Date>
|
|
>new C<Date>() : C<Date>
|
|
>C : typeof C
|
|
>Date : Date
|
|
>f : () => number
|
|
|
|
interface I<T extends Date> {
|
|
>I : I<T>
|
|
>T : T
|
|
>Date : Date
|
|
|
|
foo: T;
|
|
>foo : T
|
|
>T : T
|
|
}
|
|
var i: I<Date>;
|
|
>i : I<Date>
|
|
>I : I<T>
|
|
>Date : Date
|
|
|
|
var r2 = i.foo.getDate();
|
|
>r2 : number
|
|
>i.foo.getDate() : number
|
|
>i.foo.getDate : () => number
|
|
>i.foo : Date
|
|
>i : I<Date>
|
|
>foo : Date
|
|
>getDate : () => number
|
|
|
|
var r2b = i.foo['getDate']();
|
|
>r2b : number
|
|
>i.foo['getDate']() : number
|
|
>i.foo['getDate'] : () => number
|
|
>i.foo : Date
|
|
>i : I<Date>
|
|
>foo : Date
|
|
>'getDate' : string
|
|
|
|
var a: {
|
|
>a : <T extends Date>() => T
|
|
|
|
<T extends Date>(): T;
|
|
>T : T
|
|
>Date : Date
|
|
>T : T
|
|
}
|
|
var r3 = a<Date>().getDate();
|
|
>r3 : number
|
|
>a<Date>().getDate() : number
|
|
>a<Date>().getDate : () => number
|
|
>a<Date>() : Date
|
|
>a : <T extends Date>() => T
|
|
>Date : Date
|
|
>getDate : () => number
|
|
|
|
var r3b = a()['getDate']();
|
|
>r3b : number
|
|
>a()['getDate']() : number
|
|
>a()['getDate'] : () => number
|
|
>a() : Date
|
|
>a : <T extends Date>() => T
|
|
>'getDate' : string
|
|
|
|
var b = {
|
|
>b : { foo: <T extends Date>(x: T) => number; }
|
|
>{ foo: <T extends Date>(x: T) => { var a = x['getDate'](); // number return a + x.getDate(); }} : { foo: <T extends Date>(x: T) => number; }
|
|
|
|
foo: <T extends Date>(x: T) => {
|
|
>foo : <T extends Date>(x: T) => number
|
|
><T extends Date>(x: T) => { var a = x['getDate'](); // number return a + x.getDate(); } : <T extends Date>(x: T) => number
|
|
>T : T
|
|
>Date : Date
|
|
>x : T
|
|
>T : T
|
|
|
|
var a = x['getDate'](); // number
|
|
>a : number
|
|
>x['getDate']() : number
|
|
>x['getDate'] : () => number
|
|
>x : T
|
|
>'getDate' : string
|
|
|
|
return a + x.getDate();
|
|
>a + x.getDate() : number
|
|
>a : number
|
|
>x.getDate() : number
|
|
>x.getDate : () => number
|
|
>x : T
|
|
>getDate : () => number
|
|
}
|
|
}
|
|
|
|
var r4 = b.foo(new Date());
|
|
>r4 : number
|
|
>b.foo(new Date()) : number
|
|
>b.foo : <T extends Date>(x: T) => number
|
|
>b : { foo: <T extends Date>(x: T) => number; }
|
|
>foo : <T extends Date>(x: T) => number
|
|
>new Date() : Date
|
|
>Date : DateConstructor
|
|
|