unified-signatures
Disallow two overloads that could be unified into one with a union or an optional/rest parameter.
Attributes
- Included in configs
- ✅ Recommended
- 🔒 Strict
- Fixable
- 🔧 Automated Fixer
- 💡 Suggestion Fixer
- 💭 Requires type information
Rule Details
This rule aims to keep the source code as maintainable as possible by reducing the amount of overloads.
Examples of code for this rule with the default options:
- ❌ Incorrect
- ✅ Correct
function x(x: number): void;
function x(x: string): void;
function y(): void;
function y(...x: number[]): void;
function x(x: number | string): void;
function y(...x: number[]): void;
.eslintrc.cjs
module.exports = {
"rules": {
"@typescript-eslint/unified-signatures": "warn"
}
};
Options
This rule accepts an options object with the following properties:
interface Options {
/**
* Whether two parameters with different names at the same index should be considered different even if their types are the same.
*/
ignoreDifferentlyNamedParameters?: boolean;
}
const defaultOptions: Options = [{ ignoreDifferentlyNamedParameters: false }];
ignoreDifferentlyNamedParameters
Examples of code for this rule with ignoreDifferentlyNamedParameters
:
- ❌ Incorrect
- ✅ Correct
function f(a: number): void;
function f(a: string): void;
function f(...a: number[]): void;
function f(...b: string[]): void;
function f(a: number): void;
function f(b: string): void;
function f(...a: number[]): void;
function f(...a: string[]): void;