Using 'never' pattern in unions? #8373
-
Is it possible to define Current Behaviour interface MyFirstType {
__typename: 'MyFirstType',
id: string;
description: string;
}
interface MySecondType {
__typename: 'MySecondType',
id: string;
url: string;
}
type MyType = MyFirstType | MySecondType; The above doesn't actually work great, due to the nature of typescript unions and with really complex unions it can become a nightmare Desired behaviour interface MyFirstType {
__typename: 'MyFirstType',
id: string;
description: string;
}
interface MySecondType {
__typename: 'MySecondType',
id: string;
url: string;
}
type MyType = MyFirstType & { url?: never } | MySecondType & { description?: never }; This pattern is extremely useful and would make using the generated types a lot easier. I can't seem to find any plugins or docs around this. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hi @chortis, While I agree with your TypeScript examples, could you provide some codegen configuration reproduction of generated types that seems not optimal to you? Thank you, |
Beta Was this translation helpful? Give feedback.
Hi @chortis,
While I agree with your TypeScript examples, could you provide some codegen configuration reproduction of generated types that seems not optimal to you?
Thank you,