Add additional error checking
This commit is contained in:
parent
e028c0fd3d
commit
88d7f23f10
|
@ -11684,7 +11684,10 @@ namespace ts {
|
||||||
|
|
||||||
const hasExplicitReturn = func.flags & NodeFlags.HasExplicitReturn;
|
const hasExplicitReturn = func.flags & NodeFlags.HasExplicitReturn;
|
||||||
|
|
||||||
if (returnType && !hasExplicitReturn) {
|
if (returnType === neverType) {
|
||||||
|
error(func.type, Diagnostics.A_function_returning_never_cannot_have_a_reachable_end_point);
|
||||||
|
}
|
||||||
|
else if (returnType && !hasExplicitReturn) {
|
||||||
// minimal check: function has syntactic return type annotation and no explicit return statements in the body
|
// minimal check: function has syntactic return type annotation and no explicit return statements in the body
|
||||||
// this function does not conform to the specification.
|
// this function does not conform to the specification.
|
||||||
// NOTE: having returnType !== undefined is a precondition for entering this branch so func.type will always be present
|
// NOTE: having returnType !== undefined is a precondition for entering this branch so func.type will always be present
|
||||||
|
@ -14821,7 +14824,7 @@ namespace ts {
|
||||||
if (func) {
|
if (func) {
|
||||||
const signature = getSignatureFromDeclaration(func);
|
const signature = getSignatureFromDeclaration(func);
|
||||||
const returnType = getReturnTypeOfSignature(signature);
|
const returnType = getReturnTypeOfSignature(signature);
|
||||||
if (strictNullChecks || node.expression) {
|
if (strictNullChecks || node.expression || returnType === neverType) {
|
||||||
const exprType = node.expression ? checkExpressionCached(node.expression) : undefinedType;
|
const exprType = node.expression ? checkExpressionCached(node.expression) : undefinedType;
|
||||||
|
|
||||||
if (func.asteriskToken) {
|
if (func.asteriskToken) {
|
||||||
|
|
|
@ -1751,6 +1751,10 @@
|
||||||
"category": "Error",
|
"category": "Error",
|
||||||
"code": 2533
|
"code": 2533
|
||||||
},
|
},
|
||||||
|
"A function returning 'never' cannot have a reachable end point.": {
|
||||||
|
"category": "Error",
|
||||||
|
"code": 2534
|
||||||
|
},
|
||||||
"JSX element attributes type '{0}' may not be a union type.": {
|
"JSX element attributes type '{0}' may not be a union type.": {
|
||||||
"category": "Error",
|
"category": "Error",
|
||||||
"code": 2600
|
"code": 2600
|
||||||
|
|
Loading…
Reference in a new issue