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

213
Views
Use typescript to extract all element type(s) from array except first

Say I have the type

type MyTypeArray = ['', 2, boolean]

How could I extract the type 2 | boolean when the array could be of an unknown length?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can infer all elements but first. Use spread tuple operator: ..., just like in plain javascript


type ExtractTail<T extends any[]> = T extends [infer _, ...infer Tail] ? Tail : never

// [2, boolean]
type MyTypeArray = ExtractTail<['', 2, boolean]>

// 2 | boolean
type Union = MyTypeArray[number]

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!