JS.TS.UNIFIED.SIGNATURES

Warns for any two overloads that could be unified into one by using a union or an optional/rest parameter

Rule Details

This rule aims to keep the source code as maintainable as possible by reducing the amount of overloads.

Options

コピー
type Options = {
  ignoreDifferentlyNamedParameters?: boolean;
};

const defaultOptions: Options = {
  ignoreDifferentlyNamedParameters: false,
};

The rule accepts an options object with the following property:

  • ignoreDifferentlyNamedParameters: whether two parameters with different names at the same index should be considered different even if their types are the same.

Examples of code for this rule with the default options:

<!--tabs-->

Incorrect

コピー
function x(x: number): void;
function x(x: string): void;
コピー
function y(): void;
function y(...x: number[]): void;

Correct

コピー
function x(x: number | string): void;
コピー
function y(...x: number[]): void;

Examples of code for this rule with ignoreDifferentlyNamedParameters:

<!--tabs-->

Incorrect

コピー
function f(a: number): void;
function f(a: string): void;
コピー
function f(...a: number[]): void;
function f(...b: string[]): void;

Correct

コピー
function f(a: number): void;
function f(b: string): void;
コピー
function f(...a: number[]): void;
function f(...a: string[]): void;

The content on this page is adapted from the ESLint User Guide. Copyright © OpenJS Foundation and other contributors, www.openjsf.org. All rights reserved. https://eslint.org/docs/rules/