no-static-only-class
Configuration
rslint.config.ts
Rule Details
A class with only static members has no instance behavior — it's effectively just a namespace for a bag of values and functions. Use a plain object instead.
This rule reports any class declaration or expression where every member is
a public static field or method. Classes that extend another class, that have
private (#name) members, that carry class-level decorators, that contain a
static {} initialization block, or that mix in any non-static member are
left alone.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Differences from ESLint
The autofix is suppressed in a few TypeScript-only cases where ESLint's algorithm would produce syntactically invalid TypeScript. The diagnostic is still reported in all of them.
- Class with type parameters (
class A<T> { ... }). ESLint's autofix yieldsconst A<T> = { ... };constdeclarations do not accept type parameters. - Property with the optional postfix
?(static a?). ESLint's autofix yields{ a?: ... }; object members cannot be declared optional (TS1162). - Property with the definite-assignment assertion postfix
!(static a! = 1). ESLint's autofix yields{ a! : ... }; the!assertion is not permitted in this context (TS1255). - Property declared with the TC39
accessorkeyword (static accessor a = 1). The keyword has no object-literal analog. - Method-like member (method, getter, setter, or constructor) declared
without a body, e.g. an overload signature
(
static a(x: number): void;). Object-literal methods must have a body.