In typescript one can do:
type Foo = string[]
but sometimes one wants to model more structured "object like" data and then one can do:
type Bar = [[name: string],[age:number],[consent:boolean]]
Map
is defined as Map<K, V>
in lib.es2015.collection.d.ts and that's simlar to how Foo
is defined above. How would one type a Map
similar to Bar
above?
const map1 = new Map();
map1.set("name",'bob');
map1.set("age",102);
map1.set("consent",true);
// as map1's type is { name: string, age: number, consent, boolean } - the compliler
// should be able to determine the type is `string`
const shouldBeString = map1.get("name");