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

168
Views
Map a union to a string literal union of the type names

I have a type like this (in this case, the user would be a custom interface):

export type ArgumentTypes = string | number | boolean | user;

now, I would like to have a type of

export type ArgumentTypeNames = "string" | "number" | "boolean" | "user";

I've tried to search around myself for a while, but I have not been able to find a way to get the name. I tried to do ${ArgumentTypes} but that didn't work.

I'm pretty new to advanced types ( Mapped, conditional, and so on ) so I would love an explanation of the answer, or of potential solutions.

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

0

AFAIK, as of today's version of TypeScript, you can't do that without an explicit mapping of string to "string", number to "number" etc. existing somewhere in your program. The mapping might look like this:

interface TypeMapping {
  string: string;
  number: number;
  boolean: boolean;
  user: user;
}

However, not all is lost. You could make this mapping the source of truth, and derive other types from it:

type ArgumentTypeNames = keyof TypeMapping;
type ArgumentTypes = TypeMapping[ArgumentTypeNames];

Try it.

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!