Skip to content

New rule proposal: no-useless-constructor #754

@MIreland

Description

@MIreland

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


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

No one assigned

    Labels

    No labels
    No labels

    Priority

    None yet

    Start date

    None yet

    Target date

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions