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

219
Visualizações
Typescript generics and returning functions

I have a function that accepts another function as an argument, and returns a function having the same input type signature, but void instead of whatever output type the inner function had. The actual code does some other things, but here's the dumbed down version of it. I just can't seem to get the types right. Here's what I have so far (I'm aware it's wrong):

export function foo<Type>(func : (_ : Type) => any) {
  return function bar(...args : Type) : void {
    func.apply(null, args)
  }
}

The first line doesn't really capture what I want it to - the entire argument list of func should be Type, not just the first argument. I can't seem to be able to do so, though. (Note that Type[] doesn't capture the intended use, since not all arguments need to be the same type.) Is this even possible given the generics that Typescript offers?

about 4 years ago · Juan Pablo Isaza
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