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

318
Vistas
Typescript: How do I define an interface for an object type's key value pair

I have an object called externalObject that has various key:value pairs.

I also have a typescript interface that is defined as the following:

interface TestObject{
   externalObject?: {}
}

My question is how do I further set the type for the externalObject's key as string and the values that are passed inside externalObject as string or number?

Note: we do not always know the key:value pairs. They vary each time.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can set any number of key/types on an interface in a similar way to assigning an object. If you don't know the property names ahead of time, you can use a dynamic key:

export interface ITestObject {
  externalObject: {
    [key: string]: string | number;
  };
}

Alternatively, you can set the property as unknown and cast it to the proper type.

about 4 years ago · Juan Pablo Isaza Denunciar
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