Properly widen type element types in inferred rest parameter types

This commit is contained in:
Anders Hejlsberg 2018-06-13 17:00:35 -07:00
parent 58d55832ed
commit cee75aa9fc

View File

@ -17959,7 +17959,8 @@ namespace ts {
}
}
const contextualType = getIndexTypeOfType(restType, IndexKind.Number) || anyType;
const types: Type[] = [];
const hasPrimitiveContextualType = maybeTypeOfKind(contextualType, TypeFlags.Primitive | TypeFlags.Index);
const types = [];
let hasSpreadExpression = false;
for (let i = index; i < argCount; i++) {
let argType = getEffectiveArgumentType(node, i);
@ -17967,7 +17968,7 @@ namespace ts {
argType = checkExpressionWithContextualType(args[i], contextualType, context);
hasSpreadExpression = hasSpreadExpression || args[i].kind === SyntaxKind.SpreadElement;
}
types.push(argType);
types.push(hasPrimitiveContextualType ? getRegularTypeOfLiteralType(argType) : getWidenedLiteralType(argType));
}
return hasSpreadExpression ? createArrayType(getUnionType(types)) : createTupleType(types);
}