I'm working with a JS Map that's defined as
let mappy = new Map<string, string[]>()
I want to add elements to the array using the key. I could do it like this:
mappy.set(theKey, mappy.get(theKey).push('somevalue'));
This seems like a lot of code just for adding an element. If I used a simple object instead, I could easily achieve the same result:
let mappy = {};
mappy[theKey] = [];
Then later on, I can simply use mappy[theKey].push('somevalue')
. However, this approach defeats the purpose of having typed objects in TypeScript.
Is there a way to add elements to the array within the map without needing to first "get" it?