Hit this odd bug in my code and I can't figure the way to get a constant time lookup from a Map when using a tuple as my key.
Hopefully this illustrates the issue, and the workaround I'm using now just to get it to work:
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 work-around:
map.forEach((value: number, key: [number, number]) => {
if(String(key) === String([0, 0])){
console.log(value); // prints 48
}
})
To compile (transpile?) I'm using:
tsc hello.ts -target es6
tsc version 2.1.6
Tried several things to make the Map.get() method to work, not having much success.