From bc709a87adde465c6c2bba450e60cdae4c712de1 Mon Sep 17 00:00:00 2001 From: Andy Date: Mon, 17 Sep 2018 15:14:09 -0700 Subject: [PATCH] Fix bug where array element is undefined (#26433) * Fix bug where array element is undefined * Better fix --- src/compiler/checker.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 78628da2749..75349ee8ef6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3470,8 +3470,8 @@ namespace ts { const arity = getTypeReferenceArity(type); const tupleConstituentNodes = mapToTypeNodes(typeArguments.slice(0, arity), context); const hasRestElement = (type.target).hasRestElement; - if (tupleConstituentNodes && tupleConstituentNodes.length > 0) { - for (let i = (type.target).minLength; i < arity; i++) { + if (tupleConstituentNodes) { + for (let i = (type.target).minLength; i < Math.min(arity, tupleConstituentNodes.length); i++) { tupleConstituentNodes[i] = hasRestElement && i === arity - 1 ? createRestTypeNode(createArrayTypeNode(tupleConstituentNodes[i])) : createOptionalTypeNode(tupleConstituentNodes[i]);