==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts (13 errors) ==== // Generic call with no parameters function noParams() { } noParams(); noParams(); noParams<{}>(); // Generic call with parameters but none use type parameter type function noGenericParams(n: string) { } noGenericParams(''); // Valid noGenericParams(''); noGenericParams<{}>(''); // Error ~~ !!! Type '{}' does not satisfy the constraint 'number'. // Generic call with multiple type parameters and only one used in parameter type annotation function someGenerics1(n: T, m: number) { } ~~~~~~~~~~~ !!! Constraint of a type parameter cannot reference any type parameter from the same type parameter list. someGenerics1(3, 4); // Valid someGenerics1(3, 4); // Error ~ !!! Argument of type 'number' is not assignable to parameter of type 'string'. someGenerics1(3, 4); // Error someGenerics1(3, 4); // Generic call with argument of function type whose parameter is of type parameter type function someGenerics2a(n: (x: T) => void) { } someGenerics2a((n: string) => n); someGenerics2a((n: string) => n); someGenerics2a((n) => n.substr(0)); function someGenerics2b(n: (x: T, y: U) => void) { } someGenerics2b((n: string, x: number) => n); someGenerics2b((n: string, t: number) => n); someGenerics2b((n, t) => n.substr(t * t)); // Generic call with argument of function type whose parameter is not of type parameter type but body/return type uses type parameter function someGenerics3(producer: () => T) { } ~~~~~~ !!! Cannot find name 'Window'. someGenerics3(() => ''); // Error someGenerics3(() => undefined); ~~~~~~ !!! Cannot find name 'Window'. someGenerics3(() => 3); // Error // 2 parameter generic call with argument 1 of type parameter type and argument 2 of function type whose parameter is of type parameter type function someGenerics4(n: T, f: (x: U) => void) { } someGenerics4(4, () => null); // Valid someGenerics4('', () => 3); someGenerics4('', (x: string) => ''); // Error ~~~~~~~~~~~~~~~~~ !!! Argument of type '(x: string) => string' is not assignable to parameter of type '(x: number) => void'. someGenerics4(null, null); // 2 parameter generic call with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type function someGenerics5(n: T, f: (x: U) => void) { } someGenerics5(4, () => null); // Valid someGenerics5('', () => 3); someGenerics5('', (x: string) => ''); // Error ~~~~~~~~~~~~~~~~~ !!! Argument of type '(x: string) => string' is not assignable to parameter of type '(x: number) => void'. someGenerics5(null, null); // Error ~~~~~~ !!! Type 'string' does not satisfy the constraint 'number'. // Generic call with multiple arguments of function types that each have parameters of the same generic type function someGenerics6(a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) { } someGenerics6(n => n, n => n, n => n); // Valid someGenerics6(n => n, n => n, n => n); someGenerics6((n: number) => n, (n: string) => n, (n: number) => n); // Error ~~~~~~~~~~~~~~~~ !!! Argument of type '(n: string) => string' is not assignable to parameter of type '(b: number) => number'. someGenerics6((n: number) => n, (n: number) => n, (n: number) => n); // Generic call with multiple arguments of function types that each have parameters of different generic type function someGenerics7(a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) { } someGenerics7(n => n, n => n, n => n); // Valid, types of n are respectively someGenerics7(n => n, n => n, n => n); someGenerics7((n: number) => n, (n: string) => n, (n: number) => n); // Generic call with argument of generic function type function someGenerics8(n: T): T { return n; } var x = someGenerics8(someGenerics7); // Error ~~~~~~~~~~~~~ !!! Argument of type '(a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void' is not assignable to parameter of type 'string'. x(null, null, null); // Error // Generic call with multiple parameters of generic type passed arguments with no best common type function someGenerics9(a: T, b: T, c: T): T { return null; } var a9a = someGenerics9('', 0, []); var a9a: {}; var a9b = someGenerics9<{ a?: number; b?: string; }>({ a: 0 }, { b: '' }, null); var a9b: { a?: number; b?: string; }; // Generic call with multiple parameters of generic type passed arguments with multiple best common types interface A91 { x: number; y?: string; } interface A92 { x: number; z?: Window; ~~~~~~ !!! Cannot find name 'Window'. } var a9e = someGenerics9(undefined, { x: 6, z: window }, { x: 6, y: '' }); ~~~~~~ !!! Cannot find name 'window'. var a9e: {}; var a9f = someGenerics9(undefined, { x: 6, z: window }, { x: 6, y: '' }); ~~~~~~ !!! Cannot find name 'window'. var a9f: A92; // Generic call with multiple parameters of generic type passed arguments with a single best common type var a9d = someGenerics9({ x: 3 }, { x: 6 }, { x: 6 }); var a9d: { x: number; }; // Generic call with multiple parameters of generic type where one argument is of type 'any' var anyVar: any; var a = someGenerics9(7, anyVar, 4); var a: any; // Generic call with multiple parameters of generic type where one argument is [] and the other is not 'any' var arr = someGenerics9([], null, undefined); var arr: any[];