From fcc2d22cf527fda94503d92d1cc17cf858e8348b Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 9 Mar 2019 06:55:14 -0800 Subject: [PATCH] Fix case where getParameterTypeAtPosition didn't return undefined for out of bounds --- src/compiler/checker.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ec544ea0950..6dfd7258605 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -21770,9 +21770,14 @@ namespace ts { return getTypeOfParameter(signature.parameters[pos]); } if (signature.hasRestParameter) { + // We want to return the value undefined for an out of bounds parameter position, + // so we need to check bounds here before calling getIndexedAccessType (which + // otherwise would return the type 'undefined'). const restType = getTypeOfSymbol(signature.parameters[paramCount]); - const indexType = getLiteralType(pos - paramCount); - return getIndexedAccessType(restType, indexType); + const index = pos - paramCount; + if (!isTupleType(restType) || restType.target.hasRestElement || index < (restType.typeArguments || emptyArray).length) { + return getIndexedAccessType(restType, getLiteralType(index)); + } } return undefined; }