Skip to content

Commit b00e6b5

Browse files
committed
Don’t widen literals based on bogus contextual type instantiation
1 parent dc325fe commit b00e6b5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21248,8 +21248,8 @@ namespace ts {
2124821248
type;
2124921249
}
2125021250

21251-
function getWidenedLiteralLikeTypeForContextualType(type: Type, contextualType: Type | undefined) {
21252-
if (!isLiteralOfContextualType(type, contextualType)) {
21251+
function getWidenedLiteralLikeTypeForContextualType(type: Type, contextualType: Type | undefined, contextNode?: Node) {
21252+
if (!isLiteralOfContextualType(type, contextualType) && !(contextNode && isLiteralOfContextualType(type, instantiateContextualType(contextualType, contextNode)))) {
2125321253
type = getWidenedUniqueESSymbolType(getWidenedLiteralType(type));
2125421254
}
2125521255
return type;
@@ -34495,7 +34495,7 @@ namespace ts {
3449534495
const type = checkExpression(node, checkMode, forceTuple);
3449634496
return isConstContext(node) || isCommonJsExportedExpression(node) ? getRegularTypeOfLiteralType(type) :
3449734497
isTypeAssertion(node) ? type :
34498-
getWidenedLiteralLikeTypeForContextualType(type, instantiateContextualType(arguments.length === 2 ? getContextualType(node) : contextualType, node));
34498+
getWidenedLiteralLikeTypeForContextualType(type, arguments.length === 2 ? getContextualType(node) : contextualType, node);
3449934499
}
3450034500

3450134501
function checkPropertyAssignment(node: PropertyAssignment, checkMode?: CheckMode): Type {

0 commit comments

Comments
 (0)