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

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

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 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!