From 6e6fbdabb1d5184f5e63d04d87c32a55c4e703d0 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 1 Jul 2021 23:36:34 +0000 Subject: [PATCH] Avoid doing subtype reduction on arrays when contextually typed by array types. --- src/compiler/checker.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 761ca7a95ec..545282638ed 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -26175,8 +26175,9 @@ namespace ts { if (forceTuple || inConstContext || contextualType && someType(contextualType, isTupleLikeType)) { return createArrayLiteralType(createTupleType(elementTypes, elementFlags, /*readonly*/ inConstContext)); } + const unionReductionStrategy = contextualType && isArrayType(contextualType) ? UnionReduction.None : UnionReduction.Subtype; return createArrayLiteralType(createArrayType(elementTypes.length ? - getUnionType(sameMap(elementTypes, (t, i) => elementFlags[i] & ElementFlags.Variadic ? getIndexedAccessTypeOrUndefined(t, numberType) || anyType : t), UnionReduction.Subtype) : + getUnionType(sameMap(elementTypes, (t, i) => elementFlags[i] & ElementFlags.Variadic ? getIndexedAccessTypeOrUndefined(t, numberType) || anyType : t), unionReductionStrategy) : strictNullChecks ? implicitNeverType : undefinedWideningType, inConstContext)); }