This rule warns when a class is accidentally used as a namespace.
From TSLint’s docs:
Users who come from a Java-style OO language may wrap their utility functions in an extra class, instead of putting them at the top level.
Examples of incorrect code for this rule:
class EmptyClass {}
class ConstructorOnly {
constructor() {
foo();
}
}
// Use an object instead:
class StaticOnly {
static version = 42;
static hello() {
console.log("Hello, world!");
}
}
Examples of correct code for this rule:
class EmptyClass extends SuperClass {}
class ParameterProperties {
constructor(public name: string) {}
}
const StaticOnly = {
version: 42,
hello() {
console.log("Hello, world!");
},
};
This rule accepts a single object option.
constructorOnly: true
will silence warnings about classes containing only a constructor.allowEmpty: true
will silence warnings about empty classes.staticOnly: true
will silence warnings about classes containing only static members.
You can disable this rule if you don’t have anyone who would make these kinds of mistakes on your team or if you use classes as namespaces.
no-unnecessary-class
from TSLint