no-useless-constructor
Disallow unnecessary constructors.
🔒
Extending "plugin:@typescript-eslint/strict"
in an ESLint configuration enables this rule.
💡
Some problems reported by this rule are manually fixable by editor suggestions.
This rule extends the base eslint/no-useless-constructor
rule.
It adds support for:
- constructors marked as
protected
/private
(i.e. marking a constructor as non-public), public
constructors when there is no superclass,- constructors with only parameter properties.
Caveat
This lint rule will report on constructors whose sole purpose is to change visibility of a parent constructor. See discussion on this rule's lack of type information for context.
Options
See eslint/no-useless-constructor
's options.
How to Use
- Flat Config
- Legacy Config
eslint.config.mjs
export default tseslint.config({
rules: {
// Note: you must disable the base rule as it can report incorrect errors
"no-useless-constructor": "off",
"@typescript-eslint/no-useless-constructor": "error"
}
});
.eslintrc.cjs
module.exports = {
"rules": {
// Note: you must disable the base rule as it can report incorrect errors
"no-useless-constructor": "off",
"@typescript-eslint/no-useless-constructor": "error"
}
};
Try this rule in the playground ↗