I'm trying to write types for the following simplified example.
How can I tell Container that the config will be derived from the component?
type Container = {
component: "A" | "B" | "C";
config: AConfig | BConfig | CConfig;
}
type App = {
containers: Container[];
}
I tried using generics, but then the containers in App cannot have multiple types.
type Config = {
A: AConfig;
B: BConfig;
C: CConfig;
}
type Container<T extends keyof Config> = {
component: T;
config: Config[T];
}
type App<T> = {
containers: Container<T>[];
}