addressed PR feedback

This commit is contained in:
Vladimir Matveev
2015-11-22 22:06:05 -08:00
parent 71b98e0615
commit 5eb8f71ee1
4 changed files with 85 additions and 6 deletions

View File

@@ -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;
}

View 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> {
}

View 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* () {
});
}

View 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> {
}