2014-09-12 22:35:07 +02:00
tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(11,17): error TS2344: Type '{}' does not satisfy the constraint 'number'.
tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(14,27): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(16,31): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(32,34): error TS2304: Cannot find name 'Window'.
tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(34,15): error TS2304: Cannot find name 'Window'.
tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(41,35): error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(x: number) => void'.
tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(48,35): error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(x: number) => void'.
tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(49,15): error TS2344: Type 'string' does not satisfy the constraint 'number'.
tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(55,41): error TS2345: Argument of type '(n: string) => string' is not assignable to parameter of type '(b: number) => number'.
tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(66,31): error TS2345: Argument of type '<A, B extends string, C>(a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void' is not assignable to parameter of type 'string'.
2014-10-28 08:28:59 +01:00
tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(73,11): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
2014-10-24 22:51:19 +02:00
Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'.
2014-09-12 22:35:07 +02:00
tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(85,9): error TS2304: Cannot find name 'Window'.
2014-10-28 08:28:59 +01:00
tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(87,11): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
2014-10-24 22:51:19 +02:00
Type argument candidate '{ x: number; z: any; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y: string; }'.
2014-09-12 22:35:07 +02:00
tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(87,47): error TS2304: Cannot find name 'window'.
tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(89,52): error TS2304: Cannot find name 'window'.
2014-10-08 22:48:44 +02:00
==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts (15 errors) ====
2014-07-13 01:04:16 +02:00
// Generic call with no parameters
function noParams<T extends {}>() { }
noParams();
noParams<string>();
noParams<{}>();
// Generic call with parameters but none use type parameter type
function noGenericParams<T extends number>(n: string) { }
noGenericParams(''); // Valid
noGenericParams<number>('');
noGenericParams<{}>(''); // Error
~~
2014-09-12 00:19:57 +02:00
!!! error TS2344: Type '{}' does not satisfy the constraint 'number'.
2014-07-13 01:04:16 +02:00
// Generic call with multiple type parameters and only one used in parameter type annotation
function someGenerics1<T, U extends T>(n: T, m: number) { }
~~~~~~~~~~~
2014-09-12 00:19:57 +02:00
!!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
2014-07-13 01:04:16 +02:00
someGenerics1(3, 4); // Valid
someGenerics1<string, number>(3, 4); // Error
2014-07-25 02:00:03 +02:00
~
2014-09-12 00:19:57 +02:00
!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
2014-07-13 01:04:16 +02:00
someGenerics1<number, {}>(3, 4); // Error
someGenerics1<number, number>(3, 4);
// Generic call with argument of function type whose parameter is of type parameter type
function someGenerics2a<T extends string>(n: (x: T) => void) { }
someGenerics2a((n: string) => n);
someGenerics2a<string>((n: string) => n);
someGenerics2a<string>((n) => n.substr(0));
function someGenerics2b<T extends string, U extends number>(n: (x: T, y: U) => void) { }
someGenerics2b((n: string, x: number) => n);
someGenerics2b<string, number>((n: string, t: number) => n);
someGenerics2b<string, number>((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<T extends Window>(producer: () => T) { }
~~~~~~
2014-09-12 00:19:57 +02:00
!!! error TS2304: Cannot find name 'Window'.
2014-07-13 01:04:16 +02:00
someGenerics3(() => ''); // Error
someGenerics3<Window>(() => undefined);
~~~~~~
2014-09-12 00:19:57 +02:00
!!! error TS2304: Cannot find name 'Window'.
2014-07-13 01:04:16 +02:00
someGenerics3<number>(() => 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<T, U extends number>(n: T, f: (x: U) => void) { }
someGenerics4(4, () => null); // Valid
someGenerics4<string, number>('', () => 3);
someGenerics4<string, number>('', (x: string) => ''); // Error
2014-07-25 02:00:03 +02:00
~~~~~~~~~~~~~~~~~
2014-09-12 00:19:57 +02:00
!!! error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(x: number) => void'.
2014-07-13 01:04:16 +02:00
someGenerics4<string, number>(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<U extends number, T>(n: T, f: (x: U) => void) { }
someGenerics5(4, () => null); // Valid
someGenerics5<number, string>('', () => 3);
someGenerics5<number, string>('', (x: string) => ''); // Error
2014-07-25 02:00:03 +02:00
~~~~~~~~~~~~~~~~~
2014-09-12 00:19:57 +02:00
!!! error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(x: number) => void'.
2014-07-13 01:04:16 +02:00
someGenerics5<string, number>(null, null); // Error
~~~~~~
2014-09-12 00:19:57 +02:00
!!! error TS2344: Type 'string' does not satisfy the constraint 'number'.
2014-07-13 01:04:16 +02:00
// Generic call with multiple arguments of function types that each have parameters of the same generic type
function someGenerics6<A extends number>(a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) { }
someGenerics6(n => n, n => n, n => n); // Valid
someGenerics6<number>(n => n, n => n, n => n);
someGenerics6<number>((n: number) => n, (n: string) => n, (n: number) => n); // Error
2014-07-25 02:00:03 +02:00
~~~~~~~~~~~~~~~~
2014-09-12 00:19:57 +02:00
!!! error TS2345: Argument of type '(n: string) => string' is not assignable to parameter of type '(b: number) => number'.
2014-07-13 01:04:16 +02:00
someGenerics6<number>((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, B extends string, C>(a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) { }
someGenerics7(n => n, n => n, n => n); // Valid, types of n are <any, string, any> respectively
someGenerics7<number, string, number>(n => n, n => n, n => n);
someGenerics7<number, string, number>((n: number) => n, (n: string) => n, (n: number) => n);
// Generic call with argument of generic function type
function someGenerics8<T extends string>(n: T): T { return n; }
var x = someGenerics8<string>(someGenerics7); // Error
2014-07-25 02:00:03 +02:00
~~~~~~~~~~~~~
2014-09-12 00:19:57 +02:00
!!! error TS2345: Argument of type '<A, B extends string, C>(a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void' is not assignable to parameter of type 'string'.
2014-07-13 01:04:16 +02:00
x<string, string, string>(null, null, null); // Error
// Generic call with multiple parameters of generic type passed arguments with no best common type
function someGenerics9<T extends any>(a: T, b: T, c: T): T {
return null;
}
var a9a = someGenerics9('', 0, []);
2014-10-22 00:32:45 +02:00
~~~~~~~~~~~~~
2014-10-28 08:28:59 +01:00
!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
2014-10-25 01:42:22 +02:00
!!! error TS2453: Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'.
2014-07-13 01:04:16 +02:00
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;
~~~~~~
2014-09-12 00:19:57 +02:00
!!! error TS2304: Cannot find name 'Window'.
2014-07-13 01:04:16 +02:00
}
var a9e = someGenerics9(undefined, { x: 6, z: window }, { x: 6, y: '' });
2014-10-22 00:32:45 +02:00
~~~~~~~~~~~~~
2014-10-28 08:28:59 +01:00
!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
2014-10-25 01:42:22 +02:00
!!! error TS2453: Type argument candidate '{ x: number; z: any; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y: string; }'.
2014-07-13 01:04:16 +02:00
~~~~~~
2014-09-12 00:19:57 +02:00
!!! error TS2304: Cannot find name 'window'.
2014-07-13 01:04:16 +02:00
var a9e: {};
var a9f = someGenerics9<A92>(undefined, { x: 6, z: window }, { x: 6, y: '' });
~~~~~~
2014-09-12 00:19:57 +02:00
!!! error TS2304: Cannot find name 'window'.
2014-07-13 01:04:16 +02:00
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[];