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

147
Vistas
Is there a way to have a map with complex keys in typescript?

So I want to implement a map with two-part keys in typescript. My key format is like this:

type Key = {
  section: number,
  index: number
}

I have tried to create a map like this:

let map = new Map<Key,Record>()

But whenever I try to get a value from the map:

cont val = map.get(myKey)

The value is undefined.

Is there any way to have a map in typescript with complex types?

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

0

Because you are using an object as a key of Map you need to make sure the reference key that you have used to set the map, is the same when you want to get from the map!

let myKey:Key = {index:1,section:2}
map.set(myKey,your object)
const val = map.get(myKey); // Now has value

But I suggest you to use primitive type as a key. So you can append section and index as new string key!

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