Merge pull request #30292 from Microsoft/fixRestSignatureRelation

Fix relation of signatures with rest parameter
This commit is contained in:
Anders Hejlsberg
2019-03-11 13:07:22 -07:00
committed by GitHub
2 changed files with 7 additions and 22 deletions

View File

@@ -21773,9 +21773,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;
}