Treat array literal contextually typed by homomorphic mapped types as in tuple context (#56555)

This commit is contained in:
Mateusz Burzyński
2023-12-14 00:12:38 +01:00
committed by GitHub
parent b527b9059a
commit 2c7162143b
5 changed files with 328 additions and 2 deletions

View File

@@ -31053,7 +31053,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const inDestructuringPattern = isAssignmentTarget(node);
const inConstContext = isConstContext(node);
const contextualType = getApparentTypeOfContextualType(node, /*contextFlags*/ undefined);
const inTupleContext = isSpreadIntoCallOrNew(node) || !!contextualType && someType(contextualType, isTupleLikeType);
const inTupleContext = isSpreadIntoCallOrNew(node) || !!contextualType && someType(contextualType, t => isTupleLikeType(t) || isGenericMappedType(t) && !t.nameType && !!getHomomorphicTypeVariable(t.target as MappedType || t));
let hasOmittedExpression = false;
for (let i = 0; i < elementCount; i++) {
const e = elements[i];