Relate a Map's key and value TypeScript types

Viewed 50

I want to relate a Map's key and value in TypeScript. The following doesn't work, but captures what I want:

interface ValueTypes {
    a: x;
    b: y;
    c: z;
}

let m = new Map<T extends keyof ValueTypes><T, ValueTypes[T]>();

Sadly, I can't seem to parameterise a Map before its generic parameters.

There could be other datastructures out there that effectuate equivalent implementations of whatever use-case my Map has. That's not what this question is about. It is specifically about TypeScript typing of the generic Map type.

0 Answers
Related