-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
typename discriminator not properly set if fragment on object type is spread onto union #4886
Comments
Understanding when a specific fragment matched is a larger problem which this enhancement could help address but would not fully solve since fragments on abstract types/interfaces would still need to be typed as Instead, to solve this problem we've leaned into requiring See https://relay.dev/docs/next/guides/alias-directive/#enforced-safety With that problem more broadly solved, doses this typing still feel worth improving? I do agree with your assessment that we could be generating more specific types in this case, I'm just not sure what complexity would be involved in enabling it. |
I like I understand the concern for the potentially added complexity though. |
I can see that a switch could be better than a series of nullable properties for modeling the behavior you have there. If I recall correctly, you logic for deciding how/when to generate a discriminated union vs an object with optional properties is complex and not necessarily rigorous. If you want to step all the way back to considering this problem from scratch, I'd be interested in hearing what if any solution you come up with that could feel more rigorous or easier to reason about. It's also perhaps noting that if we did have cases where we could confidently understand that we would generate a discriminated union, we could avoid requiring |
The above fragments currently leads to the following TypeScript definition for the
someUnion
fragment:I would've expected it to be the following:
To achieve the same result you currently have to define your fragment like this:
Having to use an additional inline fragment seems unnecessary, since the fragments are already defined on a concrete object type.
The text was updated successfully, but these errors were encountered: