Skip to main content

unified-signatures

Disallow two overloads that could be unified into one with a union or an optional/rest parameter.

🔒

Extending "plugin:@typescript-eslint/strict" in an ESLint configuration enables this rule.

Function overload signatures are a TypeScript way to define a function that can be called in multiple very different ways. Overload signatures add syntax and theoretical bloat, so it's generally best to avoid using them when possible. Switching to union types and/or optional or rest parameters can often avoid the need for overload signatures.

This rule reports when function overload signatures can be replaced by a single function signature.

.eslintrc.cjs
module.exports = {
"rules": {
"@typescript-eslint/unified-signatures": "error"
}
};
Try this rule in the playground ↗

Examples

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

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:

function f(a: number): void;
function f(a: string): void;

Options

Resources