Skip to content

Commit

Permalink
unified-signatures: Can't unify rest parameters (palantir#2874)
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-hanson authored and adidahiya committed Jun 5, 2017
1 parent d802bd7 commit a88462d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
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

0 comments on commit a88462d

Please sign in to comment.