I would like to create a static Map which will contain key value pairs which are of both strings. This key value pair is never going to change.
Something like follows:
static KEY_VALUE_PAIR: Map<string, string>: {
'space' : 'jump',
'enter' : 'hit'
}
When I do this, I get an error saying Type '{ 'space': string; }' is not assignable to type 'Map<string, string>'.
Am I doing something wrong here?
If I remove the return type Map<string, string>
, it's a plain object and it works fine.
A static map in Typescript can be created and initialized inline by creating a new Map object like this:
const KEY_VALUE_PAIR = new Map<string, string>([
['space','jump'],
['enter','hit']
]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With