TypeScript/tests/baselines/reference/genericCallWithObjectTypeArgsAndConstraints4.errors.txt
2014-07-24 19:39:50 -07:00

40 lines
1.3 KiB
Plaintext

==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints4.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) {
~~~~~~~~~~~
!!! Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
return (x: T) => t2;
}
var c: C;
var d: D;
var r = foo(c, d);
var r2 = foo(d, c); // error because C does not extend D
var r3 = foo(c, { x: '', foo: c });
var r4 = foo(null, null);
var r5 = foo({}, null);
var r6 = foo(null, {});
var r7 = foo({}, {});
var r8 = foo(() => { }, () => { });
var r9 = foo(() => { }, () => 1);
function other<T, U extends T>() {
~~~~~~~~~~~
!!! Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
var r4 = foo(c, d);
var r5 = foo<T, U>(c, d); // error
~
!!! Argument of type 'C' is not assignable to parameter of type 'T'.
}