Seeking to retrieve the union type of generics within an array, but currently only able to access what the generic is extended from rather than the actual implementation.
type Params = Record<string, number | string | null | undefined> | undefined;
type Route<T extends Params = undefined> = {
params: T
}
type Stack = {
routes: Route<Params>[];
}
const route1: Route<{ detailUrl: string }> = { ... };
const route2: Route<{ head: string }> = { ... };
const route3: Route = { ... };
const routeRegistry: Stack = {
routes: [route1, route2, route3]
};
type UnionOfParams = ExtractGeneric<typeof routeRegistry['routes'][number]>;
// expected: { detailUrl: string } | { head: string } | undefined
// received: Params
While const assertion can limit widening of inference types, it did not yield results in this case.
No relevant solutions have been found for this specific issue. Are there any methods to achieve the desired outcome?