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

208
Views
How to set typescript type for key value in objects?

I have an object of currency types with properties like this:

CurrencyType = {
  usd: {
    country: 'United States', 
    symbol: '$USD', 
    icon: <USD />
  }, 
  cad: {
    country: 'Canada', 
    symbol: '$CAD', 
    icon: <CAD />
  },
  etc...
}

How can I write the type so that it takes a dynamic value for the key of each object – usd, or cad

I am trying to find how I can set the typescript type for for this object above so that the object names are included.

Basically want something like this:

export interface CurrencyTypes {

   [currencyName: string]: {
      country: string;
      symbol: string;
      icon: React.ReactNode; 
   }
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

I believe you're looking for something like this where you iterate over the values of another type.


type CountryCurrency = "usd" | "cad" | "aud";

export interface CurrencyTypes {
   [Currency in CountryCurrency]: {
      country: string;
      symbol: string;
      icon: React.ReactNode; 
   }
}

This will require that any object that implements the CurrencyTypes interface has all of the keys that are possible values of CountryCurrency

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!