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
- Rewrite `interface I { foo(): void; }` as `interface I { foo: () => void; }`
- Run `oxlint --fix` to convert signatures mechanically
- 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
- Write interface members for functions in property form from the start: `foo: () => void`
- Run `oxlint --fix` when enabling the rule to convert existing shorthand
- Remember the variance rationale: property signatures are what makes strictFunctionTypes meaningful on interfaces
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
- Use a method signature instead of a property signature.
- Type can be trivially inferred from the initializer
- Prefer using inline type specifiers instead of a top-level t
- Prefer using a top-level type-only import instead of inline
- Prefer using a top-level type-only import instead of inline
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/aad13c232679e126.
Report an issue: GitHub.