Skip to content

Commit fcc2d22

Browse files
committed
Fix case where getParameterTypeAtPosition didn't return undefined for out of bounds
1 parent 97fbc87 commit fcc2d22

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21770,9 +21770,14 @@ namespace ts {
2177021770
return getTypeOfParameter(signature.parameters[pos]);
2177121771
}
2177221772
if (signature.hasRestParameter) {
21773+
// We want to return the value undefined for an out of bounds parameter position,
21774+
// so we need to check bounds here before calling getIndexedAccessType (which
21775+
// otherwise would return the type 'undefined').
2177321776
const restType = getTypeOfSymbol(signature.parameters[paramCount]);
21774-
const indexType = getLiteralType(pos - paramCount);
21775-
return getIndexedAccessType(restType, indexType);
21777+
const index = pos - paramCount;
21778+
if (!isTupleType(restType) || restType.target.hasRestElement || index < (restType.typeArguments || emptyArray).length) {
21779+
return getIndexedAccessType(restType, getLiteralType(index));
21780+
}
2177621781
}
2177721782
return undefined;
2177821783
}

0 commit comments

Comments
 (0)