-
-
Notifications
You must be signed in to change notification settings - Fork 61
Description
Summary
This is a proposal to implement the TypeScript extension of ESLint's no-useless-constructor rule.
Note: This issue was opened by an AI assistant (Claude, by Anthropic) on behalf of a user who identified this gap while auditing typescript-eslint extension rule coverage in tsgolint.
Rule description
@typescript-eslint/no-useless-constructor extends the base ESLint rule to understand TypeScript-specific constructor patterns that make a constructor useless:
- Parameter properties — a constructor whose only body is parameter property declarations (e.g.
constructor(private x: string) {}) is not useless in TypeScript, and the TS version correctly avoids false positives here - Visibility modifiers — a constructor that only changes access level (e.g.
protected constructor() { super(); }) may or may not be useless; the TS version flags these (with a known caveat: type information would be needed to fully resolve this) - Empty constructors with no superclass — the base rule handles these; the TS extension ensures TypeScript-specific inheritance patterns don't cause false positives
Without this rule (or with the base ESLint rule enabled instead), TypeScript projects get either false positives (base rule flags valid TS patterns) or no coverage at all.
Example
// ✅ OK — parameter property, NOT useless
class Foo {
constructor(private x: string) {}
}
// ❌ Error — useless, only calls super with same args
class Bar extends Foo {
constructor(x: string) {
super(x);
}
}
// ❌ Error — empty constructor, no superclass
class Baz {
constructor() {}
}Motivation
This is one of 18 typescript-eslint extension rules (🧱) not yet covered by tsgolint. It's a commonly-enabled rule in TypeScript strict configs (plugin:@typescript-eslint/strict) and is a direct replacement for the base ESLint rule — users migrating from ESLint would expect it to be available.
Configuration
No options required. When enabling this rule, users should disable the base ESLint rule:
{
"no-useless-constructor": "off",
"@typescript-eslint/no-useless-constructor": "error"
}References
- typescript-eslint rule docs: https://typescript-eslint.io/rules/no-useless-constructor
- Base ESLint rule: https://eslint.org/docs/latest/rules/no-useless-constructor
Related coverage gaps
While auditing typescript-eslint extension rules (🧱) against tsgolint, the following rules are also missing. Listing here for visibility — happy to open separate issues if useful:
| Rule | Notes |
|---|---|
no-unused-expressions |
partial type-awareness |
class-methods-use-this |
|
default-param-last |
|
init-declarations |
|
max-params |
|
no-array-constructor |
|
no-dupe-class-members |
|
no-empty-function |
|
no-invalid-this |
|
no-loop-func |
|
no-loss-of-precision |
|
no-magic-numbers |
|
no-redeclare |
|
no-restricted-imports |
|
no-shadow |
|
no-unused-vars |
|
no-use-before-define |
(prefer-destructuring is already tracked as planned.)
Metadata
Metadata
Assignees
Labels
Type
Fields
Give feedbackPriority
Start date
Target date
Effort