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

73
Views
Typescript cast array of object to a linear type

I'm a beginner in the fabulous world of type creation in typescript and I have a little problem.

I have a array of obects

type foo = [
  {name:"aa", type:"string", usless:"cc", ...},
  {name:"aaaa", type:"number", ...},
  {name:"aaa", usless:"cc", ...}
]

my goal is to transform my type foo to a reduce one

type reduceFoo = transformArray<foo>
//    ^? {name:"aa",type:string}|{name:"aaaa",type:number}|{name:"aaa"}

One of the tricky things is that when the type attribute is not defined, I want it not to be in the final type.

I tried to loop on foo with {[U in foo]:Pick<U,'name'|'type'>} but this is not the right way to do it

And finally I have a function that transforms a string into a type (stringToType<T:string>) but I want to apply it only on the type attribute of the object. But I have no idea when to call him

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