Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

324
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda