@@ -12419,11 +12419,6 @@ namespace ts {
12419
12419
return promiseType;
12420
12420
}
12421
12421
12422
- function checkReturnExpression(node: Expression, contextualMapper?: TypeMapper): Type {
12423
- const type = checkExpressionCached(node, contextualMapper);
12424
- return isUnitType(type) && !hasLiteralContextualType(node) ? getBaseTypeOfLiteralType(type) : type;
12425
- }
12426
-
12427
12422
function getReturnTypeFromBody(func: FunctionLikeDeclaration, contextualMapper?: TypeMapper): Type {
12428
12423
const contextualSignature = getContextualSignatureForFunctionLikeDeclaration(func);
12429
12424
if (!func.body) {
@@ -12433,7 +12428,7 @@ namespace ts {
12433
12428
const isAsync = isAsyncFunctionLike(func);
12434
12429
let type: Type;
12435
12430
if (func.body.kind !== SyntaxKind.Block) {
12436
- type = checkReturnExpression (<Expression>func.body, contextualMapper);
12431
+ type = checkExpressionCached (<Expression>func.body, contextualMapper);
12437
12432
if (isAsync) {
12438
12433
// From within an async function you can return either a non-promise value or a promise. Any
12439
12434
// Promise/A+ compatible implementation will always assimilate any foreign promise, so the
@@ -12477,6 +12472,9 @@ namespace ts {
12477
12472
if (!contextualSignature) {
12478
12473
reportErrorsFromWidening(func, type);
12479
12474
}
12475
+ if (isUnitType(type) && !(contextualSignature && isLiteralContextualType(getReturnTypeOfSignature(contextualSignature)))) {
12476
+ type = getBaseTypeOfLiteralType(type);
12477
+ }
12480
12478
12481
12479
const widenedType = getWidenedType(type);
12482
12480
// From within an async function you can return either a non-promise value or a promise. Any
@@ -12491,7 +12489,7 @@ namespace ts {
12491
12489
forEachYieldExpression(<Block>func.body, yieldExpression => {
12492
12490
const expr = yieldExpression.expression;
12493
12491
if (expr) {
12494
- let type = checkReturnExpression (expr, contextualMapper);
12492
+ let type = checkExpressionCached (expr, contextualMapper);
12495
12493
12496
12494
if (yieldExpression.asteriskToken) {
12497
12495
// A yield* expression effectively yields everything that its operand yields
@@ -12541,7 +12539,7 @@ namespace ts {
12541
12539
forEachReturnStatement(<Block>func.body, returnStatement => {
12542
12540
const expr = returnStatement.expression;
12543
12541
if (expr) {
12544
- let type = checkReturnExpression (expr, contextualMapper);
12542
+ let type = checkExpressionCached (expr, contextualMapper);
12545
12543
if (isAsync) {
12546
12544
// From within an async function you can return either a non-promise value or a promise. Any
12547
12545
// Promise/A+ compatible implementation will always assimilate any foreign promise, so the
@@ -13455,8 +13453,7 @@ namespace ts {
13455
13453
return links.resolvedType;
13456
13454
}
13457
13455
13458
- function hasLiteralContextualType(node: Expression) {
13459
- let contextualType = getContextualType(node);
13456
+ function isLiteralContextualType(contextualType: Type) {
13460
13457
if (contextualType) {
13461
13458
if (contextualType.flags & TypeFlags.TypeParameter) {
13462
13459
const apparentType = getApparentTypeOfTypeParameter(<TypeParameter>contextualType);
@@ -13475,7 +13472,7 @@ namespace ts {
13475
13472
13476
13473
function checkExpressionForMutableLocation(node: Expression, contextualMapper?: TypeMapper): Type {
13477
13474
const type = checkExpression(node, contextualMapper);
13478
- return hasLiteralContextualType( node) ? type : getBaseTypeOfLiteralType(type);
13475
+ return isLiteralContextualType(getContextualType( node) ) ? type : getBaseTypeOfLiteralType(type);
13479
13476
}
13480
13477
13481
13478
function checkPropertyAssignment(node: PropertyAssignment, contextualMapper?: TypeMapper): Type {
0 commit comments