I'm using graphql-code-generator to generate TypeScript definitions from my GraphQL queries and currently trying to extract a specific union from an array. Is this possible in TypeScript? I've found an example where someone extracted a type from a generic and tried to make use if the Extract
function, but this does not work and returns 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"}>