2014-07-13 01:04:16 +02:00
|
|
|
==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints5.ts (3 errors) ====
|
|
|
|
// Generic call with constraints infering type parameter from object member properties
|
|
|
|
|
|
|
|
class C {
|
|
|
|
x: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
class D {
|
|
|
|
x: string;
|
|
|
|
y: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
function foo<T, U extends T>(t: T, t2: 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
|
|
|
return (x: T) => t2;
|
|
|
|
}
|
|
|
|
|
|
|
|
var c: C;
|
|
|
|
var d: D;
|
|
|
|
var r2 = foo(d, c); // the constraints are self-referencing, no downstream error
|
|
|
|
var r9 = foo(() => 1, () => { }); // the constraints are self-referencing, no downstream error
|
|
|
|
|
|
|
|
function other<T, U extends T>() {
|
|
|
|
~~~~~~~~~~~
|
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 r5 = foo<T, U>(c, d); // error
|
2014-07-25 02:00:03 +02:00
|
|
|
~
|
2014-09-12 00:19:57 +02:00
|
|
|
!!! error TS2345: Argument of type 'C' is not assignable to parameter of type 'T'.
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
|