'Write generic multi-dimensional Map type
I'd like to create a generic multi-dimensional map type where the last of N types is the final value and the preceding types will effectively be a key.
In other words:
let m:MDMap<Coat,Pie,Date,Location>;
//...
m.get(myWoolCoat,myApplePie,yesterday) // returns a Location
Without variadic generics though it looks like I'm going to end up with something like this:
export type MultiMap<
A extends any,
B extends any,
C = void,
D = void,
// ... etc.
> = D extends void
? C extends void
? Map<A,B>
: Map<A,Map<B,C>>
: Map<A,Map<B,Map<C,D>>>
let m:MultiMap<Coat,Pie,Date,Location>;
I know Typescript handles variadic tuple types but I haven't been able to bridge that ability to something resembling the above desire.
Should I make do with the work-around or is there some way to pull off some kind recursive generic?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
