48 lines
No EOL
2.9 KiB
Text
48 lines
No EOL
2.9 KiB
Text
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithNonSymmetricSubtypes.ts(12,9): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
|
|
Type argument candidate '{ x: number; y?: number; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; z?: number; }'.
|
|
Property 'y' is missing in type '{ x: number; z?: number; }'.
|
|
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithNonSymmetricSubtypes.ts(13,10): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
|
|
Type argument candidate '{ x: number; z?: number; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y?: number; }'.
|
|
Property 'z' is missing in type '{ x: number; y?: number; }'.
|
|
|
|
|
|
==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithNonSymmetricSubtypes.ts (2 errors) ====
|
|
// generic type argument inference where inference leads to two candidates that are both supertypes of all candidates
|
|
// we choose the first candidate so the result is dependent on the order of the arguments provided
|
|
|
|
function foo<T>(x: T, y: T) {
|
|
var r: T;
|
|
return r;
|
|
}
|
|
|
|
var a: { x: number; y?: number; };
|
|
var b: { x: number; z?: number; };
|
|
|
|
var r = foo(a, b); // { x: number; y?: number; };
|
|
~~~
|
|
!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
|
|
!!! error TS2453: Type argument candidate '{ x: number; y?: number; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; z?: number; }'.
|
|
!!! error TS2453: Property 'y' is missing in type '{ x: number; z?: number; }'.
|
|
var r2 = foo(b, a); // { x: number; z?: number; };
|
|
~~~
|
|
!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
|
|
!!! error TS2453: Type argument candidate '{ x: number; z?: number; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y?: number; }'.
|
|
!!! error TS2453: Property 'z' is missing in type '{ x: number; y?: number; }'.
|
|
|
|
var x: { x: number; };
|
|
var y: { x?: number; };
|
|
|
|
var r3 = foo(a, x); // { x: number; y?: number; };
|
|
var r4 = foo(x, a); // { x: number; };
|
|
|
|
var r5 = foo(a, y); // { x?: number; };
|
|
var r5 = foo(y, a); // { x?: number; };
|
|
|
|
var r6 = foo(x, y); // { x?: number; };
|
|
var r6 = foo(y, x); // { x?: number; };
|
|
|
|
var s1: (x: Object) => string;
|
|
var s2: (x: string) => string;
|
|
|
|
var r7 = foo(s1, s2); // (x: Object) => string;
|
|
var r8 = foo(s2, s1); // (x: string) => string; |