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

112
Vistas
Unable to index typescript object

This is what I have:

export const ID1 = "id1";
export const ID2 = "id2";
export const ID3 = "id3";

export const MAPPING1 = "MAPPING1";
export const MAPPING2 = "MAPPING2";
export const MAPPING3 = "MAPPING3";

export const MAPPINGS = {
    ID1: MAPPING1,
    ID2: MAPPING2,
    ID3: MAPPING3
};
const finalMapping = MAPPINGS[key as keyof typeof MAPPINGS] || "NOTFOUND"

where key is a string. I've printed out test values like so:

console.log("key = " + key + " with type: " + (typeof key));
// prints this: key = ID1 with type: string

But finalMapping ends up always being NOTFOUND for me. Why am I unable to index the MAPPINGS object properly?

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

0

Not sure why this works, but it does:

export const MAPPINGS = {
    ID1: MAPPING1,
    ID2: MAPPING2,
    ID3: MAPPING3
};

to

export const MAPPINGS = {
    [ID1]: MAPPING1,
    [ID2]: MAPPING2,
    [ID3]: MAPPING3
};
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