139 lines
No EOL
4.7 KiB
Text
139 lines
No EOL
4.7 KiB
Text
tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements.ts(4,1): error TS2354: No best common type exists among return expressions.
|
|
tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements.ts(12,1): error TS2354: No best common type exists among return expressions.
|
|
tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements.ts(22,1): error TS2354: No best common type exists among return expressions.
|
|
tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements.ts(31,1): error TS2354: No best common type exists among return expressions.
|
|
tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements.ts(43,1): error TS2354: No best common type exists among return expressions.
|
|
tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements.ts(48,1): error TS2354: No best common type exists among return expressions.
|
|
tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements.ts(56,1): error TS2354: No best common type exists among return expressions.
|
|
tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements.ts(56,13): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
|
|
tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements.ts(56,26): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
|
|
|
|
|
|
==== tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements.ts (9 errors) ====
|
|
// return type of a function with multiple returns is the BCT of each return statement
|
|
// it is an error if there is no single BCT, these are error cases
|
|
|
|
function f1() {
|
|
~~~~~~~~~~~~~~~
|
|
if (true) {
|
|
~~~~~~~~~~~~~~~
|
|
return 1;
|
|
~~~~~~~~~~~~~~~~~
|
|
} else {
|
|
~~~~~~~~~~~~
|
|
return '';
|
|
~~~~~~~~~~~~~~~~~~
|
|
}
|
|
~~~~~
|
|
}
|
|
~
|
|
!!! error TS2354: No best common type exists among return expressions.
|
|
|
|
function f2() {
|
|
~~~~~~~~~~~~~~~
|
|
if (true) {
|
|
~~~~~~~~~~~~~~~
|
|
return 1;
|
|
~~~~~~~~~~~~~~~~~
|
|
} else if (false) {
|
|
~~~~~~~~~~~~~~~~~~~~~~~
|
|
return 2;
|
|
~~~~~~~~~~~~~~~~~
|
|
} else {
|
|
~~~~~~~~~~~~
|
|
return '';
|
|
~~~~~~~~~~~~~~~~~~
|
|
}
|
|
~~~~~
|
|
}
|
|
~
|
|
!!! error TS2354: No best common type exists among return expressions.
|
|
|
|
function f3() {
|
|
~~~~~~~~~~~~~~~
|
|
try {
|
|
~~~~~~~~~
|
|
return 1;
|
|
~~~~~~~~~~~~~~~~~
|
|
}
|
|
~~~~~
|
|
catch (e) {
|
|
~~~~~~~~~~~~~~~
|
|
return '';
|
|
~~~~~~~~~~~~~~~~~~
|
|
}
|
|
~~~~~
|
|
}
|
|
~
|
|
!!! error TS2354: No best common type exists among return expressions.
|
|
|
|
function f4() {
|
|
~~~~~~~~~~~~~~~
|
|
try {
|
|
~~~~~~~~~
|
|
return 1;
|
|
~~~~~~~~~~~~~~~~~
|
|
}
|
|
~~~~~
|
|
catch (e) {
|
|
~~~~~~~~~~~~~~~
|
|
|
|
|
|
}
|
|
~~~~~
|
|
finally {
|
|
~~~~~~~~~~~~~
|
|
return '';
|
|
~~~~~~~~~~~~~~~~~~
|
|
}
|
|
~~~~~
|
|
}
|
|
~
|
|
!!! error TS2354: No best common type exists among return expressions.
|
|
|
|
function f5() {
|
|
~~~~~~~~~~~~~~~
|
|
return 1;
|
|
~~~~~~~~~~~~~
|
|
return '';
|
|
~~~~~~~~~~~~~~
|
|
}
|
|
~
|
|
!!! error TS2354: No best common type exists among return expressions.
|
|
|
|
function f6<T, U>(x: T, y:U) {
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
if (true) {
|
|
~~~~~~~~~~~~~~~
|
|
return x;
|
|
~~~~~~~~~~~~~~~~~
|
|
} else {
|
|
~~~~~~~~~~~~
|
|
return y;
|
|
~~~~~~~~~~~~~~~~~
|
|
}
|
|
~~~~~
|
|
}
|
|
~
|
|
!!! error TS2354: No best common type exists among return expressions.
|
|
|
|
function f8<T extends U, U extends V, V>(x: T, y: U) {
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
~~~~~~~~~~~
|
|
!!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
|
|
~~~~~~~~~~~
|
|
!!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
|
|
if (true) {
|
|
~~~~~~~~~~~~~~~
|
|
return x;
|
|
~~~~~~~~~~~~~~~~~
|
|
} else {
|
|
~~~~~~~~~~~~
|
|
return y;
|
|
~~~~~~~~~~~~~~~~~
|
|
}
|
|
~~~~~
|
|
}
|
|
~
|
|
!!! error TS2354: No best common type exists among return expressions.
|
|
|