Improve DX around TS Codegen #1033
blittle
started this conversation in
Ideas + Feature Requests
Replies: 1 comment
-
TIL the NonNullable utility can help bypass the function MyComponent({variants}: NonNullable<VariantsQuery['product']>['variants']) {
...
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In building the
VariantSelector
component I've encountered some issues with our type codegen. For example, say you have a query for a product:Now I'd like to create a component that consumes the type that will be generated for that query. I can import
VariantsQuery
from'storefrontapi.generated'
to get access to the whole type. But in this case, I really only care about the variants type within the query. But I cannot get at that type easily. For example:This will produce an error, because
product
is not garanteed to be defined. It could be null if an invalid handle is passed in the query. But I still want to get at the generated type underneath the hood if it is defined. How do I do that? In this case, because a fragment is used, the codegen also generates a fragment typeProductVariantFragment
. But there isn't always a fragment available. And I found this extremely confusing and difficult to deal with. How could we improve this DX?Beta Was this translation helpful? Give feedback.
All reactions