src/content/docs/linter/rules/use-unified-type-signatures.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="TypeScript and TSX" icon="seti:typescript"> ## Summary - Rule available since: `v2.1.0` - Diagnostic Category: [`lint/style/useUnifiedTypeSignatures`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule has an [**unsafe**](/linter/#unsafe-fixes) fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`@typescript-eslint/unified-signatures`](https://typescript-eslint.io/rules/unified-signatures){
"linter": {
"rules": {
"style": {
"useUnifiedTypeSignatures": "error"
}
}
}
}
Disallow overload signatures that can be unified into a single signature.
Overload signatures that can be merged into a single signature are redundant and should be avoided. This rule helps simplify function signatures by combining overloads by making parameters optional and/or using type unions.
function f(a: number): void;
function f(a: string): void;
function f({ a }: Record<"a", string>): void;
function f({ a }: Record<"a", boolean>): void;
function f(obj: any): void {};
type T = {
a(): void;
a(x: number): void;
}
interface I {
(): void;
(x: number): void;
}
export function fizzbuzz([fizz, buzz]: [number, number]): void;
export function fizzbuzz([fizz, buzz]: [string, string]): void;
export default function fizzbuzz([fizz, buzz]: [string | number, string | number]): void {}
function f(a: number | string): void {}
function f({ a }: Record<"a", string | boolean>): void;
interface I {
a(x?: number): void;
}
export function fizzbuzz([fizz, buzz]: [number, number] | [string, string]): void;
export default function fizzbuzz([fizz, buzz]: [string | number, string | number]): void {}
Different return types cannot be merged:
interface I {
f(): void;
f(x: number): number;
}
Different type parameters cannot be merged:
function f<T extends number>(x: T): void;
function f<T extends string>(x: T): void;
function f(x: unknown): void {}
Different rest signatures cannot be merged: (cf https://github.com/microsoft/TypeScript/issues/5077)
function foo(...x: string[]): void;
function foo(...x: number[]): void;
function foo(...x: any[]): void {}
ignoreDifferentlyNamedParametersIf set to true, overloads with differently named parameters will be ignored,
even if said parameters would be of otherwise mergeable types.
Parameter declarations that lack specified "names" (such as array spread and destructuring literals) will be ignored for this check.
Default: false
{
"linter": {
"rules": {
"style": {
"useUnifiedTypeSignatures": {
"options": {
"ignoreDifferentlyNamedParameters": true
}
}
}
}
}
}
function bake(numApples: number): void;
function bake(cakeType: string): void;
ignoreDifferentJsDocIf set to true, overloads with different JSDoc comments from one another will be ignored.
Ones with identical comments will be merged as normal.
Default: false
{
"linter": {
"rules": {
"style": {
"useUnifiedTypeSignatures": {
"options": {
"ignoreDifferentJsDoc": true
}
}
}
}
}
}
/** Print foo + 1 */
function doThing(foo: number): void;
/** Print foo concatenated with 3 */
function doThing(foo: string): void;
/** @deprecated - don't use this, it crashes the program */
function doThing(foo: boolean): void;