Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

308
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda