I got multiple interfaces, say Int1, Int2 and so on
interface Int1 {}
interface Int2 {}
And I want to create a registry, structured as
const Registry = {
"Int1": {
"obj1": {} as Int1,
"obj2": {} as Int1,
},
"Int2": {
"obj1": {} as Int2,
},
}
AFAIK TypeScript requires the key type to be a literal. If I define my interface names as literals, how can I use these literals to reference the actual interface as type? Seems like I could the it with mapped types but I cannot figure it out myself.
Like
type RegistryType = {
[theKey in "Int1" | "Int2"]: {
[x: string]: <<force the interfaces Int1 or Int2 respecting theKey>>
}
}