I'm having trouble declaring the value of a value in a key-value pair of a map in TypeScript.
map: {
key: someStruct
}
I would like to declare the type of someStruct
while initializing it at the same time. How do I do this?
I'm having trouble declaring the value of a value in a key-value pair of a map in TypeScript.
map: {
key: someStruct
}
I would like to declare the type of someStruct
while initializing it at the same time. How do I do this?
You can use it like this, and assign it if you want also to some variable x
let x = new Map([
["key", ["val1"]],
["key2", ["val2"]]
]);
I don't know the whole object, but here's how you can do it.
This is your Interfaces
interface Struct {
...
}
interface Map {
key: Struct
}
const map: Map {
key: someStruct
}
or if you don't have access to the whole object
map: <Map>({
key: someStruct
})
// or
map: {
key: someStruct
} as Map