Skip to content

Commit 26416c3

Browse files
committed
Allow spreading arrays after required parameters
This allows: 1. Spreading arrays into all-optional parameters whose types match. 2. Spreading arrays into parameter lists that are too short and whose body presumably uses `arguments`.
1 parent 1a7c193 commit 26416c3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9598,6 +9598,10 @@ namespace ts {
95989598
return signature.hasRestParameter && parameterIndex >= signature.parameters.length - 1;
95999599
}
96009600

9601+
function areAllParametersOptionalAfter(signature: Signature, parameterIndex: number) {
9602+
return parameterIndex >= signature.minArgumentCount;
9603+
}
9604+
96019605
function isSupertypeOfEach(candidate: Type, types: Type[]): boolean {
96029606
for (const t of types) {
96039607
if (candidate !== t && !isTypeSubtypeOf(t, candidate)) return false;
@@ -14649,7 +14653,7 @@ namespace ts {
1464914653
// If spread arguments are present, check that they correspond to a rest parameter. If so, no
1465014654
// further checking is necessary.
1465114655
if (spreadArgIndex >= 0) {
14652-
return isRestParameterIndex(signature, spreadArgIndex);
14656+
return isRestParameterIndex(signature, spreadArgIndex) || areAllParametersOptionalAfter(signature, spreadArgIndex);
1465314657
}
1465414658

1465514659
// Too many arguments implies incorrect arity.

0 commit comments

Comments
 (0)