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

271
Visualizações
Typescript abstract method doesn't inherit the params type

I have the following code:

abstract class Foo<T extends { data: string }> {
  abstract doSomething(params: T): void;
} 


class Baz extends Foo<{ id: string; data: string }> {
   doSomething(params) {}
}

My expectation is that when implementing the doSomething method it'll automatically infer the params as T, but it infers it as any. Am I wrong?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

By extending, the compiler just checks whether the derived class is assignable to the base class, you are free to design the derived class as long as it is assignable to the base class.

Imagine you are not extending, just writing a regular class. doSomething(param) does implicitly means doSomething(param:any). This implication dose not change even when you are extending. Since (any) => void is assignable to ({ id: string; data: string }) => void , everything is fine. The compiler won't do extra work.

over 4 years ago · Santiago Trujillo 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