Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

307
Views
Eslint, no useless constructor with super() inside?

code:

  constructor(cdr: ChangeDetectorRef, inj: Injector) {
    super(cdr, inj);
  }

eslint:

 {
   ...
   overrides: {
      ...
      rules: {
        ...
        "@typescript-eslint/no-useless-constructor": "error",
        ...
      }
   }
}

This rule is telling me to remove useless constructor, but I must call super() inside.

How can I bypass this rule without disabling or removing it?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Just remove the constructor. It's not necessary to define it if you have no further use. For your extended class, it's the same as an empty constructor. It's useless since it's automatically handled by JavaScript/TypeScript. See docs.

If you don't provide your own constructor, then a default constructor will be supplied for you. ... If your class is a derived class, the default constructor calls the parent constructor, passing along any arguments that were provided.

So yes constructors for derived classes must contain a super call. But you don't necessarily have to define an empty constructor or just super inside (derived classes). Unless you want to add more or different signature.

If you still want to keep it, just remove/disable the linter rule.

There is a Caveat to know:

This lint rule will report on constructors whose sole purpose is to change visibility of a parent constructor. -- TS Docs also see ES Docs

Angular may need this "useless" constructor with super call for e.g. Injectable and Constructor (derived classes). This can cause the error: This constructor is not compatible with Angular Dependency Injection because its dependency at index 0 of the parameter list is invalid. In this case, the eslint rule must be disabled.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!