Merge pull request #6512 from masaeedu/allowMissingReturnForVoidAnyUnion

Allow missing return for void any union
This commit is contained in:
Mohamed Hegazy
2016-01-25 15:12:40 -08:00
6 changed files with 52 additions and 6 deletions

View File

@@ -10404,7 +10404,8 @@ namespace ts {
/*
*TypeScript Specification 1.0 (6.3) - July 2014
* An explicitly typed function whose return type isn't the Void or the Any type
* An explicitly typed function whose return type isn't the Void type,
* the Any type, or a union type containing the Void or Any type as a constituent
* 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
@@ -10415,7 +10416,7 @@ namespace ts {
}
// Functions with with an explicitly specified 'void' or 'any' return type don't need any return expressions.
if (returnType === voidType || isTypeAny(returnType)) {
if (returnType === voidType || isTypeAny(returnType) || (returnType && (returnType.flags & TypeFlags.Union) && someConstituentTypeHasKind(returnType, TypeFlags.Any | TypeFlags.Void))) {
return;
}