0

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?

emilyl
  • 11
  • 2
  • Possible duplicate of [ES6 Map in Typescript](https://stackoverflow.com/questions/30019542/es6-map-in-typescript) – msanford Jul 12 '19 at 01:50

2 Answers2

0

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"]]
    ]);
Mohamed Sweelam
  • 1,109
  • 8
  • 22
0

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
tscpp
  • 1,298
  • 2
  • 12
  • 35