Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!