Check return type includes 'undefined' in function with implicit return

This commit is contained in:
Anders Hejlsberg 2016-03-05 16:16:19 -08:00
parent d0e4b4ae35
commit 129a4f1908
2 changed files with 7 additions and 0 deletions

View File

@ -11095,6 +11095,9 @@ namespace ts {
// NOTE: having returnType !== undefined is a precondition for entering this branch so func.type will always be present
error(func.type, Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value);
}
else if (returnType && strictNullChecks && !isTypeAssignableTo(undefinedType, returnType)) {
error(func.type, Diagnostics.Function_lacks_ending_return_statement_and_return_type_does_not_include_undefined);
}
else if (compilerOptions.noImplicitReturns) {
if (!returnType) {
// If return type annotation is omitted check if function has any explicit return statements.

View File

@ -1091,6 +1091,10 @@
"category": "Error",
"code": 2365
},
"Function lacks ending return statement and return type does not include 'undefined'.": {
"category": "Error",
"code": 2366
},
"Type parameter name cannot be '{0}'": {
"category": "Error",
"code": 2368