typescript/prefer-class-method
Prefer class methods over untyped arrow-function class properties.
Targeted pattern scope
This rule targets class property definitions whose value is an arrow function and whose property itself has no explicit type annotation.
What this rule reports
This rule reports class property arrow functions that have no explicit property type annotation.
Why this rule exists
Method syntax is often clearer for class behavior and avoids extra per-instance function property declarations.
❌ Incorrect
class C {
value = () => {};
}
✅ Correct
class C {
value(): void {}
}
Behavior and migration notes
This rule reports only and does not provide an autofix.
A typed function property (for example x: () => void = () => {}) is not
reported by this rule.
Options
This rule has no options.
Additional examples
class C {
handler: () => void = () => {};
}
// ✅ valid (explicit property type annotation)
ESLint flat config example
import etcMisc from "eslint-plugin-etc-misc";
export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/typescript/prefer-class-method": "error",
},
},
];
When not to use it
Disable this rule if class-property arrow functions are your preferred pattern.
Package documentation
Rule catalog ID: R104
Further reading
Adoption resources
- Start at warning level in CI, then move to error after cleanup.
- Use focused codemods/autofix batches per package or directory.