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

323
Views
How to define dynamic types based on a key in typescript

I want to define a type for the following data structure

[
  {
   type:'email',
   email:'test@gmai.com'
  },
  {
   type:'username',
   username:'user@123'
  },
  {
   type:'ssoId',
   ssoId:'client@123'
  }
]

As we can see the other keys in the object are based on the type. What is the best way to define type for such structures.

I was thinking of the following

interface Email{
    type:'email',
    email: string;
}

interface UserName{
    type:'username',
    username: string;
}

interface SSOId{
    type:'ssoId',
    ssoId: string;
}

type FinalType=Email|UserName|SSOId

Is this the best way to define FinalType? I want to use this interface in other places too.

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!