{"record":{"id":"3abd0b422631a0ff","repo":"oxc-project/oxc","slug":"these-overloads-can-be-combined-into-one-signature-3abd0b","errorCode":null,"errorMessage":"These overloads can be combined into one signature with an optional parameter.","messagePattern":"These overloads can be combined into one signature with an optional parameter\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/typescript/unified_signatures.rs","lineNumber":30,"sourceCode":"};\nuse oxc_diagnostics::{LabeledSpan, OxcDiagnostic};\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse rustc_hash::{FxHashMap, FxHashSet};\nuse schemars::JsonSchema;\nuse serde::{Deserialize, Serialize};\n\nuse crate::{\n    AstNode,\n    context::{ContextHost, LintContext},\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn unified_signatures_diagnostic<L: Into<LabeledSpan>, T: IntoIterator<Item = L>>(\n    message: String,\n    labels: T,\n) -> OxcDiagnostic {\n    OxcDiagnostic::warn(message).with_labels(labels)\n}\n\n#[derive(Debug, Default, Clone, Deserialize, Serialize, JsonSchema)]\n#[serde(default, rename_all = \"camelCase\", deny_unknown_fields)]\npub struct UnifiedSignaturesOptions {\n    /// Whether to ignore parameter name differences when comparing signatures. If `false`, signatures\n    /// will not be considered unifiable if they have parameters in the same position with different\n    /// names, even if the parameter types are the same.\n    ignore_differently_named_parameters: bool,\n    /// Whether to ignore JSDoc differences when comparing signatures. If `false`, signatures will not\n    /// be considered unifiable if the closest leading block comments for the signatures are different,\n    /// even if the signatures themselves are identical.\n    #[serde(rename = \"ignoreOverloadsWithDifferentJSDoc\")]\n    ignore_overloads_with_different_jsdoc: bool,\n}\n\n#[derive(Debug, Default, Clone, Deserialize, Serialize)]\npub struct UnifiedSignatures(UnifiedSignaturesOptions);","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/typescript/unified_signatures.rs#L12-L48","documentation":"Diagnostic from oxlint's `typescript/unified-signatures` rule. This variant fires when exactly two overloads differ only by trailing parameter(s) that can be omitted: parameter types match up to the common prefix and the longer signature's extra trailing parameter is a plain (non-rest) parameter, so the pair collapses into one signature with an optional parameter (`b?: T`). The diagnostic labels the extra parameter 'this parameter only appears in one overload' and the shorter signature's last parameter 'matching overload ends here'.","triggerScenarios":"Two same-named signatures such as `function parse(input: string): void;` and `function parse(input: string, flags: number): void;` — same parameter types on the shared prefix, all parameters after the divergence point omittable (optional), and the shorter signature not ending in a rest parameter.","commonSituations":"APIs that grew an optional argument over time (locale, timeout, options) by appending an overload instead of making the parameter optional; generated .d.ts output; teams new to the typescript preset in oxlint.","solutions":["Merge into one signature with an optional parameter: `function parse(input: string, flags?: number): void;`.","If the overloads carry different JSDoc intentionally, enable `ignoreOverloadsWithDifferentJSDoc`.","Enable `ignoreDifferentlyNamedParameters` if only the parameter names differ.","Suppress once with an inline disable comment if the split is semantically meaningful."],"exampleFix":"// before\ndeclare function createDate(ts: number): Date;\ndeclare function createDate(ts: number, locale: string): Date;\n// after\ndeclare function createDate(ts: number, locale?: string): Date;","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Extend the existing signature with `param?: T` instead of adding an overload for an optional trailing argument.","Avoid overload pairs that differ only by trailing parameters — collapse them at authoring time.","Let the type checker confirm call sites still resolve after merging before deleting the shorter overload."],"tags":["oxlint","lint","typescript","overloads","optional-parameters","style"],"backgroundTag":"typescript-overload-unification","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}