126 lines
4.5 KiB
Plaintext
126 lines
4.5 KiB
Plaintext
==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts (18 errors) ====
|
|
// checking whether other types are subtypes of type parameters with constraints
|
|
|
|
class Foo { foo: number; }
|
|
function f<T extends Foo, U extends Foo, V>(t: T, u: U, v: V) {
|
|
// error
|
|
var r = true ? t : u;
|
|
~~~~~~~~~~~~
|
|
!!! error TS2367: No best common type exists between 'T' and 'U'.
|
|
var r = true ? u : t;
|
|
~~~~~~~~~~~~
|
|
!!! error TS2367: No best common type exists between 'U' and 'T'.
|
|
|
|
// error
|
|
var r2 = true ? t : v;
|
|
~~~~~~~~~~~~
|
|
!!! error TS2367: No best common type exists between 'T' and 'V'.
|
|
var r2 = true ? v : t;
|
|
~~~~~~~~~~~~
|
|
!!! error TS2367: No best common type exists between 'V' and 'T'.
|
|
|
|
// error
|
|
var r3 = true ? v : u;
|
|
~~~~~~~~~~~~
|
|
!!! error TS2367: No best common type exists between 'V' and 'U'.
|
|
var r3 = true ? u : v;
|
|
~~~~~~~~~~~~
|
|
!!! error TS2367: No best common type exists between 'U' and 'V'.
|
|
|
|
// ok
|
|
var r4 = true ? t : new Foo();
|
|
var r4 = true ? new Foo() : t;
|
|
|
|
// ok
|
|
var r5 = true ? u : new Foo();
|
|
var r5 = true ? new Foo() : u;
|
|
|
|
// BUG, should be error
|
|
var r6 = true ? v : new Foo();
|
|
~~~~~~~~~~~~~~~~~~~~
|
|
!!! error TS2367: No best common type exists between 'V' and 'Foo'.
|
|
var r6 = true ? new Foo() : v;
|
|
~~~~~~~~~~~~~~~~~~~~
|
|
!!! error TS2367: No best common type exists between 'Foo' and 'V'.
|
|
|
|
}
|
|
|
|
class B1<T> {
|
|
foo: T;
|
|
}
|
|
|
|
class D1<T extends Foo, U extends Foo, V> extends B1<Foo> {
|
|
[x: string]: Foo;
|
|
foo: T; // ok
|
|
}
|
|
|
|
class D2<T extends Foo, U extends Foo, V> extends B1<Foo> {
|
|
[x: string]: Foo;
|
|
foo: U; // ok
|
|
}
|
|
|
|
class D3<T extends Foo, U extends Foo, V> extends B1<Foo> {
|
|
~~
|
|
!!! error TS2416: Class 'D3<T, U, V>' incorrectly extends base class 'B1<Foo>':
|
|
!!! error TS2416: Types of property 'foo' are incompatible:
|
|
!!! error TS2416: Type 'V' is not assignable to type 'Foo':
|
|
!!! error TS2416: Property 'foo' is missing in type '{}'.
|
|
[x: string]: Foo;
|
|
foo: V; // error
|
|
~~~~~~~
|
|
!!! error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'Foo'.
|
|
}
|
|
|
|
class D4<T extends Foo, U extends Foo, V> extends B1<T> {
|
|
[x: string]: T;
|
|
foo: T; // ok
|
|
}
|
|
|
|
class D5<T extends Foo, U extends Foo, V> extends B1<T> {
|
|
~~
|
|
!!! error TS2416: Class 'D5<T, U, V>' incorrectly extends base class 'B1<T>':
|
|
!!! error TS2416: Types of property 'foo' are incompatible:
|
|
!!! error TS2416: Type 'U' is not assignable to type 'T'.
|
|
[x: string]: T;
|
|
foo: U; // error
|
|
~~~~~~~
|
|
!!! error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'.
|
|
}
|
|
|
|
class D6<T extends Foo, U extends Foo, V> extends B1<T> {
|
|
~~
|
|
!!! error TS2416: Class 'D6<T, U, V>' incorrectly extends base class 'B1<T>':
|
|
!!! error TS2416: Types of property 'foo' are incompatible:
|
|
!!! error TS2416: Type 'V' is not assignable to type 'T'.
|
|
[x: string]: T;
|
|
foo: V; // error
|
|
~~~~~~~
|
|
!!! error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'.
|
|
}
|
|
|
|
class D7<T extends Foo, U extends Foo, V> extends B1<U> {
|
|
~~
|
|
!!! error TS2416: Class 'D7<T, U, V>' incorrectly extends base class 'B1<U>':
|
|
!!! error TS2416: Types of property 'foo' are incompatible:
|
|
!!! error TS2416: Type 'T' is not assignable to type 'U'.
|
|
[x: string]: U;
|
|
foo: T; // error
|
|
~~~~~~~
|
|
!!! error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'.
|
|
}
|
|
|
|
class D8<T extends Foo, U extends Foo, V> extends B1<U> {
|
|
[x: string]: U;
|
|
foo: U; // ok
|
|
}
|
|
|
|
class D9<T extends Foo, U extends Foo, V> extends B1<U> {
|
|
~~
|
|
!!! error TS2416: Class 'D9<T, U, V>' incorrectly extends base class 'B1<U>':
|
|
!!! error TS2416: Types of property 'foo' are incompatible:
|
|
!!! error TS2416: Type 'V' is not assignable to type 'U'.
|
|
[x: string]: U;
|
|
foo: V; // error
|
|
~~~~~~~
|
|
!!! error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'.
|
|
} |