41 lines
1.8 KiB
Text
41 lines
1.8 KiB
Text
|
==== tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts (8 errors) ====
|
||
|
// conditional expressions return the best common type of the branches plus contextual type (using the first candidate if multiple BCTs exist)
|
||
|
// these are errors
|
||
|
|
||
|
class Base { foo: string; }
|
||
|
class Derived extends Base { bar: string; }
|
||
|
class Derived2 extends Base { baz: string; }
|
||
|
var base: Base;
|
||
|
var derived: Derived;
|
||
|
var derived2: Derived2;
|
||
|
|
||
|
var r2 = true ? 1 : '';
|
||
|
~~~~~~~~~~~~~
|
||
|
!!! No best common type exists between 'number' and 'string'.
|
||
|
var r9 = true ? derived : derived2;
|
||
|
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||
|
!!! No best common type exists between 'Derived' and 'Derived2'.
|
||
|
|
||
|
function foo<T, U>(t: T, u: U) {
|
||
|
return true ? t : u;
|
||
|
~~~~~~~~~~~~
|
||
|
!!! No best common type exists between 'T' and 'U'.
|
||
|
}
|
||
|
|
||
|
function foo2<T extends U, U>(t: T, u: U) { // Error for referencing own type parameter
|
||
|
~~~~~~~~~~~
|
||
|
!!! Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
|
||
|
return true ? t : u; // Ok because BCT(T, U) = U
|
||
|
~~~~~~~~~~~~
|
||
|
!!! No best common type exists between 'T' and 'U'.
|
||
|
}
|
||
|
|
||
|
function foo3<T extends U, U extends V, V>(t: T, u: U) {
|
||
|
~~~~~~~~~~~
|
||
|
!!! Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
|
||
|
~~~~~~~~~~~
|
||
|
!!! Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
|
||
|
return true ? t : u;
|
||
|
~~~~~~~~~~~~
|
||
|
!!! No best common type exists between 'T' and 'U'.
|
||
|
}
|