256 lines
5 KiB
Text
256 lines
5 KiB
Text
=== tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstraintSatisfaction.ts ===
|
|
// satisfaction of a constraint to Function, no errors expected
|
|
|
|
function foo<T extends Function>(x: T): T { return x; }
|
|
>foo : <T extends Function>(x: T) => T
|
|
>T : T
|
|
>Function : Function
|
|
>x : T
|
|
>T : T
|
|
>T : T
|
|
>x : T
|
|
|
|
interface I {
|
|
>I : I
|
|
|
|
(): string;
|
|
}
|
|
var i: I;
|
|
>i : I
|
|
>I : I
|
|
|
|
class C {
|
|
>C : C
|
|
|
|
foo: string;
|
|
>foo : string
|
|
}
|
|
|
|
var a: { (): string };
|
|
>a : () => string
|
|
|
|
var b: { new (): string };
|
|
>b : new () => string
|
|
|
|
var c: { (): string; (x): string };
|
|
>c : { (): string; (x: any): string; }
|
|
>x : any
|
|
|
|
var r = foo(new Function());
|
|
>r : Function
|
|
>foo(new Function()) : Function
|
|
>foo : <T extends Function>(x: T) => T
|
|
>new Function() : Function
|
|
>Function : FunctionConstructor
|
|
|
|
var r1 = foo((x) => x);
|
|
>r1 : (x: any) => any
|
|
>foo((x) => x) : (x: any) => any
|
|
>foo : <T extends Function>(x: T) => T
|
|
>(x) => x : (x: any) => any
|
|
>x : any
|
|
>x : any
|
|
|
|
var r2 = foo((x: string[]) => x);
|
|
>r2 : (x: string[]) => string[]
|
|
>foo((x: string[]) => x) : (x: string[]) => string[]
|
|
>foo : <T extends Function>(x: T) => T
|
|
>(x: string[]) => x : (x: string[]) => string[]
|
|
>x : string[]
|
|
>x : string[]
|
|
|
|
var r3 = foo(function (x) { return x });
|
|
>r3 : (x: any) => any
|
|
>foo(function (x) { return x }) : (x: any) => any
|
|
>foo : <T extends Function>(x: T) => T
|
|
>function (x) { return x } : (x: any) => any
|
|
>x : any
|
|
>x : any
|
|
|
|
var r4 = foo(function (x: string[]) { return x });
|
|
>r4 : (x: string[]) => string[]
|
|
>foo(function (x: string[]) { return x }) : (x: string[]) => string[]
|
|
>foo : <T extends Function>(x: T) => T
|
|
>function (x: string[]) { return x } : (x: string[]) => string[]
|
|
>x : string[]
|
|
>x : string[]
|
|
|
|
var r5 = foo(i);
|
|
>r5 : I
|
|
>foo(i) : I
|
|
>foo : <T extends Function>(x: T) => T
|
|
>i : I
|
|
|
|
var r6 = foo(C);
|
|
>r6 : typeof C
|
|
>foo(C) : typeof C
|
|
>foo : <T extends Function>(x: T) => T
|
|
>C : typeof C
|
|
|
|
var r7 = foo(b);
|
|
>r7 : new () => string
|
|
>foo(b) : new () => string
|
|
>foo : <T extends Function>(x: T) => T
|
|
>b : new () => string
|
|
|
|
var r8 = foo(c);
|
|
>r8 : { (): string; (x: any): string; }
|
|
>foo(c) : { (): string; (x: any): string; }
|
|
>foo : <T extends Function>(x: T) => T
|
|
>c : { (): string; (x: any): string; }
|
|
|
|
interface I2<T> {
|
|
>I2 : I2<T>
|
|
>T : T
|
|
|
|
(x: T): T;
|
|
>x : T
|
|
>T : T
|
|
>T : T
|
|
}
|
|
var i2: I2<string>;
|
|
>i2 : I2<string>
|
|
>I2 : I2<T>
|
|
|
|
class C2<T> {
|
|
>C2 : C2<T>
|
|
>T : T
|
|
|
|
foo: T;
|
|
>foo : T
|
|
>T : T
|
|
}
|
|
|
|
var a2: { <T>(x: T): T };
|
|
>a2 : <T>(x: T) => T
|
|
>T : T
|
|
>x : T
|
|
>T : T
|
|
>T : T
|
|
|
|
var b2: { new <T>(x: T): T };
|
|
>b2 : new <T>(x: T) => T
|
|
>T : T
|
|
>x : T
|
|
>T : T
|
|
>T : T
|
|
|
|
var c2: { <T>(x: T): T; <T>(x: T, y: T): T };
|
|
>c2 : { <T>(x: T): T; <T>(x: T, y: T): T; }
|
|
>T : T
|
|
>x : T
|
|
>T : T
|
|
>T : T
|
|
>T : T
|
|
>x : T
|
|
>T : T
|
|
>y : T
|
|
>T : T
|
|
>T : T
|
|
|
|
var r9 = foo(<U>(x: U) => x);
|
|
>r9 : <U>(x: U) => U
|
|
>foo(<U>(x: U) => x) : <U>(x: U) => U
|
|
>foo : <T extends Function>(x: T) => T
|
|
><U>(x: U) => x : <U>(x: U) => U
|
|
>U : U
|
|
>x : U
|
|
>U : U
|
|
>x : U
|
|
|
|
var r10 = foo(function <U>(x: U) { return x; });
|
|
>r10 : <U>(x: U) => U
|
|
>foo(function <U>(x: U) { return x; }) : <U>(x: U) => U
|
|
>foo : <T extends Function>(x: T) => T
|
|
>function <U>(x: U) { return x; } : <U>(x: U) => U
|
|
>U : U
|
|
>x : U
|
|
>U : U
|
|
>x : U
|
|
|
|
var r11 = foo(<U extends Date>(x: U) => x);
|
|
>r11 : <U extends Date>(x: U) => U
|
|
>foo(<U extends Date>(x: U) => x) : <U extends Date>(x: U) => U
|
|
>foo : <T extends Function>(x: T) => T
|
|
><U extends Date>(x: U) => x : <U extends Date>(x: U) => U
|
|
>U : U
|
|
>Date : Date
|
|
>x : U
|
|
>U : U
|
|
>x : U
|
|
|
|
var r12 = foo(<U, V>(x: U, y: V) => x);
|
|
>r12 : <U, V>(x: U, y: V) => U
|
|
>foo(<U, V>(x: U, y: V) => x) : <U, V>(x: U, y: V) => U
|
|
>foo : <T extends Function>(x: T) => T
|
|
><U, V>(x: U, y: V) => x : <U, V>(x: U, y: V) => U
|
|
>U : U
|
|
>V : V
|
|
>x : U
|
|
>U : U
|
|
>y : V
|
|
>V : V
|
|
>x : U
|
|
|
|
var r13 = foo(i2);
|
|
>r13 : I2<string>
|
|
>foo(i2) : I2<string>
|
|
>foo : <T extends Function>(x: T) => T
|
|
>i2 : I2<string>
|
|
|
|
var r14 = foo(C2);
|
|
>r14 : typeof C2
|
|
>foo(C2) : typeof C2
|
|
>foo : <T extends Function>(x: T) => T
|
|
>C2 : typeof C2
|
|
|
|
var r15 = foo(b2);
|
|
>r15 : new <T>(x: T) => T
|
|
>foo(b2) : new <T>(x: T) => T
|
|
>foo : <T extends Function>(x: T) => T
|
|
>b2 : new <T>(x: T) => T
|
|
|
|
var r16 = foo(c2);
|
|
>r16 : { <T>(x: T): T; <T>(x: T, y: T): T; }
|
|
>foo(c2) : { <T>(x: T): T; <T>(x: T, y: T): T; }
|
|
>foo : <T extends Function>(x: T) => T
|
|
>c2 : { <T>(x: T): T; <T>(x: T, y: T): T; }
|
|
|
|
interface F2 extends Function { foo: string; }
|
|
>F2 : F2
|
|
>Function : Function
|
|
>foo : string
|
|
|
|
var f2: F2;
|
|
>f2 : F2
|
|
>F2 : F2
|
|
|
|
var r17 = foo(f2);
|
|
>r17 : F2
|
|
>foo(f2) : F2
|
|
>foo : <T extends Function>(x: T) => T
|
|
>f2 : F2
|
|
|
|
function foo2<T extends { (): void }, U extends { (): void }>(x: T, y: U) {
|
|
>foo2 : <T extends () => void, U extends () => void>(x: T, y: U) => void
|
|
>T : T
|
|
>U : U
|
|
>x : T
|
|
>T : T
|
|
>y : U
|
|
>U : U
|
|
|
|
foo(x);
|
|
>foo(x) : T
|
|
>foo : <T extends Function>(x: T) => T
|
|
>x : T
|
|
|
|
foo(y);
|
|
>foo(y) : U
|
|
>foo : <T extends Function>(x: T) => T
|
|
>y : U
|
|
}
|
|
//function foo2<T extends { (): void }, U extends T>(x: T, y: U) {
|
|
// foo(x);
|
|
// foo(y);
|
|
//}
|