153 lines
2.5 KiB
Text
153 lines
2.5 KiB
Text
=== tests/cases/conformance/types/typeParameters/typeArgumentLists/constraintSatisfactionWithAny.ts ===
|
|
// any is not a valid type argument unless there is no constraint, or the constraint is any
|
|
|
|
function foo<T extends String>(x: T): T { return null; }
|
|
>foo : <T extends String>(x: T) => T
|
|
>T : T
|
|
>String : String
|
|
>x : T
|
|
>T : T
|
|
>T : T
|
|
>null : null
|
|
|
|
function foo2<T extends { x: number }>(x: T): T { return null; }
|
|
>foo2 : <T extends { x: number; }>(x: T) => T
|
|
>T : T
|
|
>x : number
|
|
>x : T
|
|
>T : T
|
|
>T : T
|
|
>null : null
|
|
|
|
//function foo3<T extends T[]>(x: T): T { return null; }
|
|
function foo4<T extends <T>(x: T) => void>(x: T): T { return null; }
|
|
>foo4 : <T extends <T>(x: T) => void>(x: T) => T
|
|
>T : T
|
|
>T : T
|
|
>x : T
|
|
>T : T
|
|
>x : T
|
|
>T : T
|
|
>T : T
|
|
>null : null
|
|
|
|
var a;
|
|
>a : any
|
|
|
|
foo(a);
|
|
>foo(a) : any
|
|
>foo : <T extends String>(x: T) => T
|
|
>a : any
|
|
|
|
foo2(a);
|
|
>foo2(a) : any
|
|
>foo2 : <T extends { x: number; }>(x: T) => T
|
|
>a : any
|
|
|
|
//foo3(a);
|
|
foo4(a);
|
|
>foo4(a) : any
|
|
>foo4 : <T extends <T>(x: T) => void>(x: T) => T
|
|
>a : any
|
|
|
|
var b: number;
|
|
>b : number
|
|
|
|
foo<any>(b);
|
|
>foo<any>(b) : any
|
|
>foo : <T extends String>(x: T) => T
|
|
>b : number
|
|
|
|
foo2<any>(b);
|
|
>foo2<any>(b) : any
|
|
>foo2 : <T extends { x: number; }>(x: T) => T
|
|
>b : number
|
|
|
|
//foo3<any>(b);
|
|
foo4<any>(b);
|
|
>foo4<any>(b) : any
|
|
>foo4 : <T extends <T>(x: T) => void>(x: T) => T
|
|
>b : number
|
|
|
|
//function foo5<T extends String, U extends T>(x: T, y: U): T { return null; }
|
|
//foo5(a, a);
|
|
//foo5<any, any>(b, b);
|
|
|
|
class C<T extends String> {
|
|
>C : C<T>
|
|
>T : T
|
|
>String : String
|
|
|
|
constructor(public x: T) { }
|
|
>x : T
|
|
>T : T
|
|
}
|
|
|
|
var c1 = new C(a);
|
|
>c1 : C<any>
|
|
>new C(a) : C<any>
|
|
>C : typeof C
|
|
>a : any
|
|
|
|
var c2 = new C<any>(b);
|
|
>c2 : C<any>
|
|
>new C<any>(b) : C<any>
|
|
>C : typeof C
|
|
>b : number
|
|
|
|
class C2<T extends { x: number }> {
|
|
>C2 : C2<T>
|
|
>T : T
|
|
>x : number
|
|
|
|
constructor(public x: T) { }
|
|
>x : T
|
|
>T : T
|
|
}
|
|
|
|
var c3 = new C2(a);
|
|
>c3 : C2<any>
|
|
>new C2(a) : C2<any>
|
|
>C2 : typeof C2
|
|
>a : any
|
|
|
|
var c4 = new C2<any>(b);
|
|
>c4 : C2<any>
|
|
>new C2<any>(b) : C2<any>
|
|
>C2 : typeof C2
|
|
>b : number
|
|
|
|
//class C3<T extends T[]> {
|
|
// constructor(public x: T) { }
|
|
//}
|
|
|
|
//var c5 = new C3(a);
|
|
//var c6 = new C3<any>(b);
|
|
|
|
class C4<T extends <T>(x:T) => T> {
|
|
>C4 : C4<T>
|
|
>T : T
|
|
>T : T
|
|
>x : T
|
|
>T : T
|
|
>T : T
|
|
|
|
constructor(public x: T) { }
|
|
>x : T
|
|
>T : T
|
|
}
|
|
|
|
var c7 = new C4(a);
|
|
>c7 : C4<any>
|
|
>new C4(a) : C4<any>
|
|
>C4 : typeof C4
|
|
>a : any
|
|
|
|
var c8 = new C4<any>(b);
|
|
>c8 : C4<any>
|
|
>new C4<any>(b) : C4<any>
|
|
>C4 : typeof C4
|
|
>b : number
|
|
|
|
|
|
|