Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

113
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda