Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

unified-signatures: Can't unify rest parameters #2874

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/rules/unifiedSignaturesRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ function signaturesDifferBySingleParameter(types1: ts.ParameterDeclaration[], ty

const a = types1[index];
const b = types2[index];
return parametersHaveEqualSigils(a, b) ? { kind: "single-parameter-difference", p0: a, p1: b } : undefined;
// Can unify `a?: string` and `b?: number`. Can't unify `...args: string[]` and `...args: number[]`.
// See https://github.com/Microsoft/TypeScript/issues/5077
return parametersHaveEqualSigils(a, b) && a.dotDotDotToken === undefined
? { kind: "single-parameter-difference", p0: a, p1: b }
: undefined;
}

/**
Expand Down
3 changes: 1 addition & 2 deletions test/rules/unified-signatures/test.d.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ interface I {
b2(x: string): void;
b2(...x: number[]): void;

// Error if both are rest parameters.
// No error if both are rest parameters. (https://github.com/Microsoft/TypeScript/issues/5077)
b3(...x: number[]): void;
b3(...x: string[]): void;
~~~~~~~~~~~~~~ [These overloads can be combined into one signature taking `number[] | string[]`.]

// Error if only one defines an optional parameter.
c(): void;
Expand Down