Skip to content

Commit 281eeac

Browse files
authored
Merge pull request #30292 from Microsoft/fixRestSignatureRelation
Fix relation of signatures with rest parameter
2 parents e906d23 + 91996b1 commit 281eeac

File tree

2 files changed

+7
-22
lines changed

2 files changed

+7
-22
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21773,9 +21773,14 @@ namespace ts {
2177321773
return getTypeOfParameter(signature.parameters[pos]);
2177421774
}
2177521775
if (signature.hasRestParameter) {
21776+
// We want to return the value undefined for an out of bounds parameter position,
21777+
// so we need to check bounds here before calling getIndexedAccessType (which
21778+
// otherwise would return the type 'undefined').
2177621779
const restType = getTypeOfSymbol(signature.parameters[paramCount]);
21777-
const indexType = getLiteralType(pos - paramCount);
21778-
return getIndexedAccessType(restType, indexType);
21780+
const index = pos - paramCount;
21781+
if (!isTupleType(restType) || restType.target.hasRestElement || index < (restType.typeArguments || emptyArray).length) {
21782+
return getIndexedAccessType(restType, getLiteralType(index));
21783+
}
2177921784
}
2178021785
return undefined;
2178121786
}

tests/baselines/reference/getParameterNameAtPosition.errors.txt

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)