I want to create a Map()
object that has a bunch of values. What is the best way to go about this? Right now I am just doing new Map<keyof Data, any>([...myArray])
. I am going to making a few different of these maps so it would be nice to have a way to be able to pass the objects data in instead of having any
as the values. Here is a very simple example.
type Data1 = {
obj: {
a: number,
b: number
},
str: string
}
const data1 = new Map<keyof Data1, any>([
['str', 'value1'],
['obj', {
a: 1,
b: 2
}]
])
type Data2 = {
obj: {
one: number,
two: number
},
bool: string
}
const data2 = new Map<keyof Data2, any>([
['bool', true],
['obj', {
one: 1,
two: 2
}]
])
Is `Map()' maybe not the best tool for this type of functionality? Should I maybe just use a regular javascript object for this type of data pattern?