From 9b526a05b305fe2ab4e5af2ff4299a11dd345e70 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 13 Aug 2018 17:21:20 -0700 Subject: [PATCH 1/2] Fix bug where array element is undefined --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f2c1c71eb6cfd..ff3cbab7894de 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3397,7 +3397,7 @@ namespace ts { const arity = getTypeReferenceArity(type); const tupleConstituentNodes = mapToTypeNodes(typeArguments.slice(0, arity), context); const hasRestElement = (type.target).hasRestElement; - if (tupleConstituentNodes && tupleConstituentNodes.length > 0) { + if (tupleConstituentNodes && tupleConstituentNodes.length >= arity) { for (let i = (type.target).minLength; i < arity; i++) { tupleConstituentNodes[i] = hasRestElement && i === arity - 1 ? createRestTypeNode(createArrayTypeNode(tupleConstituentNodes[i])) : From 4d9d9f79ae9b1431cdac4e8b9ee48122df5fff8c Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 17 Sep 2018 10:23:35 -0700 Subject: [PATCH 2/2] 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 ff3cbab7894de..f01e245350a4d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3397,8 +3397,8 @@ namespace ts { const arity = getTypeReferenceArity(type); const tupleConstituentNodes = mapToTypeNodes(typeArguments.slice(0, arity), context); const hasRestElement = (type.target).hasRestElement; - if (tupleConstituentNodes && tupleConstituentNodes.length >= arity) { - 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]);