2014-10-25 01:42:22 +02:00
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3.ts(18,10): 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 'Derived' is not a valid type argument because it is not a supertype of candidate 'Derived2'.
2014-09-12 22:35:07 +02:00
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3.ts(20,29): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
2014-10-08 22:48:44 +02:00
==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3.ts (2 errors) ====
2014-07-13 01:04:16 +02:00
// Generic call with constraints infering type parameter from object member properties
class Base {
x: string;
}
class Derived extends Base {
y: string;
}
class Derived2 extends Base {
z: string;
}
function f<T extends Base>(a: { x: T; y: T }) {
var r: T;
return r;
}
2014-10-22 23:49:23 +02:00
var r1 = f({ x: new Derived(), y: new Derived2() }); // error because neither is supertype of the other
2014-10-22 00:32:45 +02:00
~
2014-10-25 01:42:22 +02:00
!!! 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 'Derived' is not a valid type argument because it is not a supertype of candidate 'Derived2'.
2014-07-13 01:04:16 +02:00
function f2<T extends Base, U extends { x: T; y: T }>(a: U) {
~~~~~~~~~~~~~~~~~~~~~~~~
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
var r: T;
return r;
}
var r2 = f2({ x: new Derived(), y: new Derived2() }); // ok
var r3 = f2({ x: new Derived(), y: new Derived2() }); // ok
function f3<T extends Base>(y: (a: T) => T, x: T) {
return y(null);
}
2014-10-22 23:49:23 +02:00
// all ok - second argument is processed before x is fixed
2014-07-13 01:04:16 +02:00
var r4 = f3(x => x, new Base());
var r5 = f3(x => x, new Derived());
var r6 = f3(x => x, null);