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

245
Views
Is it possible to get types from an unknown array?

I am getting Icon names from an imported library and mapping through them like this:

import * as Icons from "@icons";

// an array of icon names ["ArrowLeft", "ArrowRight" ect]
const IconNames = [...Object.keys(Icons).map((icon) => icon)] as const; 
// for sizes prop
const IconSizes = ["sm", "md", "lg"] as const; 

But when I try to get types from the array it just comes up as string:

icon: typeof IconNames[number]; //this is type string
size: typeof IconSizes[number]; //this is type "sm" | "md" | "lg"
};

Am I doing something wrong or is it not possible to get the type for icon from an unknown array "ArrowLeft" | "ArrowRight"?

Any help would be great.

Thanks

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Yeh this is a gap in TypeScript: https://github.com/microsoft/TypeScript/pull/12253#issuecomment-263132208.

Your only choice is to cast it to keyof Icons.

about 4 years ago · Santiago Gelvez 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!