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

162
Visualizações
Type args in typescript

I have this situation in my typescript code:

const first = (value: any[]) => {

}
const test = (...args: any[]) => first(...args);

In function test I pass all params in first function. first(...args).

Doing this I get a typescript error: A spread argument must either have a tuple type or be passed to a rest parameter.(2556).

I notice many answers on this topic but they don't solve my issue.

How to solve this issue?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

The error means that you need to use an Array and spread arg within it:

const first = (value: any[]) => {};
const test = (...args: any[]) => first([...args]);

Playground Link

about 4 years ago · Juan Pablo Isaza Relatório

0

Your first() function expects to get an array/tuple.
So you can simply pass the array.

const first = (value: any[]) => {};
const test = (...args: any[]) => first(args);

Playground

or you can make the first method accept variable arguments:

const first = (...value: any[]) => {};
const test = (...args: any[]) => first(...args);

Playground

about 4 years ago · Juan Pablo Isaza Relatório

0

Call first with args

const test = (...args: any[]) => first(args);
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