I'm currently utilizing graphql-code-generator to automatically generate TypeScript definitions from my GraphQL queries. I have a specific union within an array that I am trying to extract in TypeScript. Is this feasible? Although I came across an example where someone extracted a type from a generic object and attempted using the Extract
function, it unfortunately returned just never
:
export type Foo = Array<(
{
id: string;
__typename: 'Data1'
}
| {
id: string;
__typename: 'Data2'
}
)>;
type MyQueryData1 = Extract<Foo, { __typename: "Data1"}>
type MyQueryData2 = Extract<Foo, { __typename: "Data2"}>