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

161
Views
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 answers
Answer question

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 Report

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 Report

0

Call first with args

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