2014-09-12 22:35:07 +02:00
tests/cases/conformance/functions/functionImplementationErrors.ts(2,10): error TS2354: No best common type exists among return expressions.
tests/cases/conformance/functions/functionImplementationErrors.ts(6,10): error TS2354: No best common type exists among return expressions.
tests/cases/conformance/functions/functionImplementationErrors.ts(10,10): error TS2354: No best common type exists among return expressions.
tests/cases/conformance/functions/functionImplementationErrors.ts(16,10): error TS2354: No best common type exists among return expressions.
tests/cases/conformance/functions/functionImplementationErrors.ts(25,16): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
tests/cases/conformance/functions/functionImplementationErrors.ts(30,17): error TS2373: Initializer of parameter 'n' cannot reference identifier 'm' declared after it.
tests/cases/conformance/functions/functionImplementationErrors.ts(35,17): error TS2373: Initializer of parameter 'n' cannot reference identifier 'm' declared after it.
tests/cases/conformance/functions/functionImplementationErrors.ts(40,28): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
2014-11-05 01:40:56 +01:00
tests/cases/conformance/functions/functionImplementationErrors.ts(49,1): error TS2354: No best common type exists among return expressions.
tests/cases/conformance/functions/functionImplementationErrors.ts(53,10): error TS2354: No best common type exists among return expressions.
tests/cases/conformance/functions/functionImplementationErrors.ts(57,11): error TS2354: No best common type exists among return expressions.
tests/cases/conformance/functions/functionImplementationErrors.ts(61,1): error TS2354: No best common type exists among return expressions.
tests/cases/conformance/functions/functionImplementationErrors.ts(65,11): error TS2354: No best common type exists among return expressions.
tests/cases/conformance/functions/functionImplementationErrors.ts(69,11): error TS2354: No best common type exists among return expressions.
2014-09-12 22:35:07 +02:00
2014-11-05 01:40:56 +01:00
==== tests/cases/conformance/functions/functionImplementationErrors.ts (14 errors) ====
2014-07-13 01:04:16 +02:00
// FunctionExpression with no return type annotation with multiple return statements with unrelated types
var f1 = function () {
~~~~~~~~~~~~~
return '';
~~~~~~~~~~~~~~
return 3;
~~~~~~~~~~~~~
};
~
2014-09-12 00:19:57 +02:00
!!! error TS2354: No best common type exists among return expressions.
2014-07-13 01:04:16 +02:00
var f2 = function x() {
~~~~~~~~~~~~~~
return '';
~~~~~~~~~~~~~~
return 3;
~~~~~~~~~~~~~
};
~
2014-09-12 00:19:57 +02:00
!!! error TS2354: No best common type exists among return expressions.
2014-07-13 01:04:16 +02:00
var f3 = () => {
~~~~~~~
return '';
~~~~~~~~~~~~~~
return 3;
~~~~~~~~~~~~~
};
~
2014-09-12 00:19:57 +02:00
!!! error TS2354: No best common type exists among return expressions.
2014-07-13 01:04:16 +02:00
// FunctionExpression with no return type annotation with return branch of number[] and other of string[]
var f4 = function () {
~~~~~~~~~~~~~
if (true) {
~~~~~~~~~~~~~~~
return [''];
~~~~~~~~~~~~~~~~~~~~
} else {
~~~~~~~~~~~~
return [1];
~~~~~~~~~~~~~~~~~~~
}
~~~~~
}
~
2014-09-12 00:19:57 +02:00
!!! error TS2354: No best common type exists among return expressions.
2014-07-13 01:04:16 +02:00
// Function implemetnation with non -void return type annotation with no return
function f5(): number {
2014-07-19 00:19:23 +02:00
~~~~~~
2014-09-12 00:19:57 +02:00
!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
2014-07-13 01:04:16 +02:00
}
var m;
// Function signature with parameter initializer referencing in scope local variable
function f6(n = m) {
~
2014-09-12 00:19:57 +02:00
!!! error TS2373: Initializer of parameter 'n' cannot reference identifier 'm' declared after it.
2014-07-13 01:04:16 +02:00
var m = 4;
}
// Function signature with initializer referencing other parameter to the right
function f7(n = m, m?) {
~
2014-09-12 00:19:57 +02:00
!!! error TS2373: Initializer of parameter 'n' cannot reference identifier 'm' declared after it.
2014-07-13 01:04:16 +02:00
}
// FunctionExpression with non -void return type annotation with a throw, no return, and other code
// Should be error but isn't
undefined === function (): number {
2014-07-30 03:21:16 +02:00
~~~~~~
2014-09-12 00:19:57 +02:00
!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
2014-07-13 01:04:16 +02:00
throw undefined;
var x = 4;
};
2014-11-05 01:40:56 +01:00
class Base { private x; }
class AnotherClass { private y; }
class Derived1 extends Base { private m; }
class Derived2 extends Base { private n; }
function f8() {
~~~~~~~~~~~~~~~
return new Derived1();
~~~~~~~~~~~~~~~~~~~~~~~~~~
return new Derived2();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
~
!!! error TS2354: No best common type exists among return expressions.
var f9 = function () {
~~~~~~~~~~~~~
return new Derived1();
~~~~~~~~~~~~~~~~~~~~~~~~~~
return new Derived2();
~~~~~~~~~~~~~~~~~~~~~~~~~~
};
~
!!! error TS2354: No best common type exists among return expressions.
var f10 = () => {
~~~~~~~
return new Derived1();
~~~~~~~~~~~~~~~~~~~~~~~~~~
return new Derived2();
~~~~~~~~~~~~~~~~~~~~~~~~~~
};
~
!!! error TS2354: No best common type exists among return expressions.
function f11() {
~~~~~~~~~~~~~~~~
return new Base();
~~~~~~~~~~~~~~~~~~~~~~
return new AnotherClass();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
~
!!! error TS2354: No best common type exists among return expressions.
var f12 = function () {
~~~~~~~~~~~~~
return new Base();
~~~~~~~~~~~~~~~~~~~~~~
return new AnotherClass();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
};
~
!!! error TS2354: No best common type exists among return expressions.
var f13 = () => {
~~~~~~~
return new Base();
~~~~~~~~~~~~~~~~~~~~~~
return new AnotherClass();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
};
~
!!! error TS2354: No best common type exists among return expressions.
2014-07-13 01:04:16 +02:00