mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-11 06:02:53 -05:00
addressed PR feedback
This commit is contained in:
@@ -9811,17 +9811,19 @@ namespace ts {
|
||||
return aggregatedTypes;
|
||||
}
|
||||
|
||||
// TypeScript Specification 1.0 (6.3) - July 2014
|
||||
// An explicitly typed function whose return type isn't the Void or the Any type
|
||||
// must have at least one return statement somewhere in its body.
|
||||
// An exception to this rule is if the function implementation consists of a single 'throw' statement.
|
||||
// @param returnType - return type of the function, can be undefined if return type is not explicitly specified
|
||||
/*
|
||||
*TypeScript Specification 1.0 (6.3) - July 2014
|
||||
* An explicitly typed function whose return type isn't the Void or the Any type
|
||||
* must have at least one return statement somewhere in its body.
|
||||
* An exception to this rule is if the function implementation consists of a single 'throw' statement.
|
||||
* @param returnType - return type of the function, can be undefined if return type is not explicitly specified
|
||||
*/
|
||||
function checkAllCodePathsInNonVoidFunctionReturnOrThrow(func: FunctionLikeDeclaration, returnType: Type): void {
|
||||
if (!produceDiagnostics) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Functions with explicitly specified return type which is either 'void' or 'any' don't need any return expressions.
|
||||
// Functions with with an explicitly specified 'void' or 'any' return type don't need any return expressions.
|
||||
if (returnType && (returnType === voidType || isTypeAny(returnType))) {
|
||||
return;
|
||||
}
|
||||
|
||||
21
tests/baselines/reference/reachabilityChecks7.errors.txt
Normal file
21
tests/baselines/reference/reachabilityChecks7.errors.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
tests/cases/compiler/reachabilityChecks7.ts(3,16): error TS7030: Not all code paths return a value.
|
||||
tests/cases/compiler/reachabilityChecks7.ts(6,9): error TS7030: Not all code paths return a value.
|
||||
|
||||
|
||||
==== tests/cases/compiler/reachabilityChecks7.ts (2 errors) ====
|
||||
|
||||
// async function without return type annotation - error
|
||||
async function f1() {
|
||||
~~
|
||||
!!! error TS7030: Not all code paths return a value.
|
||||
}
|
||||
|
||||
let x = async function() {
|
||||
~~~~~
|
||||
!!! error TS7030: Not all code paths return a value.
|
||||
}
|
||||
|
||||
// async function with which promised type is void - return can be omitted
|
||||
async function f2(): Promise<void> {
|
||||
|
||||
}
|
||||
42
tests/baselines/reference/reachabilityChecks7.js
Normal file
42
tests/baselines/reference/reachabilityChecks7.js
Normal file
@@ -0,0 +1,42 @@
|
||||
//// [reachabilityChecks7.ts]
|
||||
|
||||
// async function without return type annotation - error
|
||||
async function f1() {
|
||||
}
|
||||
|
||||
let x = async function() {
|
||||
}
|
||||
|
||||
// async function with which promised type is void - return can be omitted
|
||||
async function f2(): Promise<void> {
|
||||
|
||||
}
|
||||
|
||||
//// [reachabilityChecks7.js]
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promise, generator) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
generator = generator.call(thisArg, _arguments);
|
||||
function cast(value) { return value instanceof Promise && value.constructor === Promise ? value : new Promise(function (resolve) { resolve(value); }); }
|
||||
function onfulfill(value) { try { step("next", value); } catch (e) { reject(e); } }
|
||||
function onreject(value) { try { step("throw", value); } catch (e) { reject(e); } }
|
||||
function step(verb, value) {
|
||||
var result = generator[verb](value);
|
||||
result.done ? resolve(result.value) : cast(result.value).then(onfulfill, onreject);
|
||||
}
|
||||
step("next", void 0);
|
||||
});
|
||||
};
|
||||
// async function without return type annotation - error
|
||||
function f1() {
|
||||
return __awaiter(this, void 0, Promise, function* () {
|
||||
});
|
||||
}
|
||||
let x = function () {
|
||||
return __awaiter(this, void 0, Promise, function* () {
|
||||
});
|
||||
};
|
||||
// async function with which promised type is void - return can be omitted
|
||||
function f2() {
|
||||
return __awaiter(this, void 0, Promise, function* () {
|
||||
});
|
||||
}
|
||||
14
tests/cases/compiler/reachabilityChecks7.ts
Normal file
14
tests/cases/compiler/reachabilityChecks7.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
// @target: ES6
|
||||
// @noImplicitReturns: true
|
||||
|
||||
// async function without return type annotation - error
|
||||
async function f1() {
|
||||
}
|
||||
|
||||
let x = async function() {
|
||||
}
|
||||
|
||||
// async function with which promised type is void - return can be omitted
|
||||
async function f2(): Promise<void> {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user