I have a type A where keys are strings and values are some datatype. (see below)
Now I want to create a Map<K,V> where K is a key of A and V is of the corresponding datatype in A. (see my attempt below)
type A = {
a: boolean,
b: number,
};
const myMap: Map<keyof A, A[keyof A]> = new Map();
myMap.set('a', 1); // bad
// only this should be allowed:
myMap.set('a', true);
myMap.set('b', 1);
My approach doesn't work since the first keyof A must not necessarily be the same as the second keyof A. What is the correct way to achieve this?