Skip to content

staticMemberOnlyClasses

Reports classes that only contain static members.

✅ This rule is included in the ts logicalStrict presets.

Classes that contain only static members are essentially being used as namespaces. In JavaScript and TypeScript, objects and module-level exports are more idiomatic and straightforward.

This rule reports on any class that only contains static members.

class MathUtils {
static PI = 3.14159;
static add(a: number, b: number) {
return a + b;
}
}
class Config {
static defaultValue = 42;
constructor() {}
}
class StaticAccessors {
static get value() {
return 42;
}
}

This rule is not configurable.

If your codebase uses classes as namespaces for organizing related static utilities, and you don’t mind the extra complexity of classes, you may want to disable this rule. Some frameworks or patterns may also require static-only classes for specific use cases. You might consider using Flint disable comments and/or configuration file disables for those specific situations instead of completely disabling this rule.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.