Encountered a strange bug in my code where I'm struggling to achieve constant time lookup from a Map when using a tuple as the key.
Here is an example highlighting the issue, along with the workaround I am currently using to make it function:
hello.ts:
let map: Map<[number, number], number> = new Map<[number, number], number>()
.set([0, 0], 48);
console.log(map.get([0,0])); // prints undefined
console.log(map.get(String([0, 0]))); // compiler: error TS2345: Argument of type
// 'string' is not assignable to parameter of type '[number, number]'.
//the workaround:
map.forEach((value: number, key: [number, number]) => {
if(String(key) === String([0, 0])){
console.log(value); // prints 48
}
})
For compilation (transpilation?), I am using:
tsc hello.ts -target es6
tsc version 2.1.6
I've experimented with different approaches to make the Map.get() method function properly, but haven't found a successful solution yet.