oxc-project/oxc · warning · OxcDiagnostic

Use a property signature instead of a method signature.

Error message

Use a property signature instead of a method signature.

What it means

typescript/method-signature-style with the default "property" style reports TSMethodSignature nodes: interface or object-type members written as method shorthand `foo(): T`. Property style `foo: () => T` is preferred because function-typed properties are checked contravariantly under strictFunctionTypes, while method shorthand is bivariant and weaker.

Source

Thrown at crates/oxc_linter/src/rules/typescript/method_signature_style.rs:29

use crate::{
    AstNode,
    context::{ContextHost, LintContext},
    rule::{DefaultRuleConfig, Rule},
};

fn method_signature_style_diagnostic(
    config: MethodSignatureStyleConfig,
    span: Span,
) -> OxcDiagnostic {
    match config {
        MethodSignatureStyleConfig::Property => method_signature_style_property_diagnostic(span),
        MethodSignatureStyleConfig::Method => method_signature_style_method_diagnostic(span),
    }
}

fn method_signature_style_property_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Use a property signature instead of a method signature.")
        .with_help("Replace the method signature with a property whose type is a function type.")
        .with_label(span)
}
fn method_signature_style_method_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Use a method signature instead of a property signature.")
        .with_help("Replace the property signature with method shorthand syntax.")
        .with_label(span)
}

#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, JsonSchema, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
enum MethodSignatureStyleConfig {
    #[default]
    /// Enforce using property signature for functions. Use this to enforce maximum correctness together with TypeScript's strict mode.
    Property,
    /// Enforce using method signature for functions. Use this if you aren't using TypeScript's strict mode and prefer this style.
    Method,
}

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Rewrite `interface I { foo(): void; }` as `interface I { foo: () => void; }`
  2. Run `oxlint --fix` to convert signatures mechanically
  3. If your team prefers shorthand (e.g. not using strict mode), configure the rule option to "method"

Example fix

// before
interface Store {
  load(key: string): Promise<Data>;
}

// after
interface Store {
  load: (key: string) => Promise<Data>;
}
Defensive patterns

Strategy: validation

Validate before calling

// .oxlintrc.json — default property style, autofix converts shorthand
{
  "rules": {
    "typescript/method-signature-style": "warn"
  }
}

Prevention

When it happens

Trigger: `interface I { foo(): void; }` or a method signature inside a type literal while the config is Property (the default); every method signature in interfaces and type literals is reported.

Common situations: Enabling strict-style presets in codebases that wrote interfaces with shorthand; porting options-object types where shorthand was idiomatic; teams aligning with the typescript-eslint default of this rule.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/aad13c232679e126. Report an issue: GitHub.