Avoid doing subtype reduction on arrays when contextually typed by array types.

This commit is contained in:
Daniel Rosenwasser 2021-07-01 23:36:34 +00:00 committed by GitHub
parent e3d6189e3a
commit 6e6fbdabb1

View File

@ -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));
}