A JavaScript Map
object has the type Map<K, V>
. I would like to create a type that matches V
.
For example:
function addItemToMap(map: Map) {
return function addItem(id: string, item: V) {
return map.set(id, item)
}
}
When I call this function, I’d like to be sure that the item I’m passing is able to be added to the map:
// This should ensure that `bar` is a value that can go into the map `foo`
addItemToMap(foo)('x', bar)
TypeScript playground with a slightly more through example