From cee75aa9fc213f8086773b15c791c8dfcca860f5 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 13 Jun 2018 17:00:35 -0700 Subject: [PATCH] Properly widen type element types in inferred rest parameter types --- src/compiler/checker.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5fa4ec5d363..e13aefc4c03 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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); }