From b00e6b51a228e15b740b0e24dcd1558fe1727c53 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 12 May 2022 09:39:19 -0700 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20widen=20literals=20based=20on?= =?UTF-8?q?=20bogus=20contextual=20type=20instantiation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/compiler/checker.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index daa45f35d76..350bff0aa8a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -21248,8 +21248,8 @@ namespace ts { type; } - function getWidenedLiteralLikeTypeForContextualType(type: Type, contextualType: Type | undefined) { - if (!isLiteralOfContextualType(type, contextualType)) { + function getWidenedLiteralLikeTypeForContextualType(type: Type, contextualType: Type | undefined, contextNode?: Node) { + if (!isLiteralOfContextualType(type, contextualType) && !(contextNode && isLiteralOfContextualType(type, instantiateContextualType(contextualType, contextNode)))) { type = getWidenedUniqueESSymbolType(getWidenedLiteralType(type)); } return type; @@ -34495,7 +34495,7 @@ namespace ts { const type = checkExpression(node, checkMode, forceTuple); return isConstContext(node) || isCommonJsExportedExpression(node) ? getRegularTypeOfLiteralType(type) : isTypeAssertion(node) ? type : - getWidenedLiteralLikeTypeForContextualType(type, instantiateContextualType(arguments.length === 2 ? getContextualType(node) : contextualType, node)); + getWidenedLiteralLikeTypeForContextualType(type, arguments.length === 2 ? getContextualType(node) : contextualType, node); } function checkPropertyAssignment(node: PropertyAssignment, checkMode?: CheckMode): Type {