Strip nulls from the form state type for maximum polaris compatability #699
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Shopify Polaris, in its infinite wisdom, accepts only
string | undefined
for thevalue
prop on its<TextInput/>
component.<input/>
in the DOM acceptsstring | readonly string[] | number | undefined;
, which you'd think Polaris would be ok with, but alas no. At runtime, it's absolutely fine to passnull
to the TextInput, it works fine, it's just the type that is not ok with it. Because Gadget's API responds withnull
, notundefined
for fields that haven't been set yet, it means that the form values type havestring | null | undefined
in them, which causes a type error by default when wiring up to a Polaris<TextInput/>
with a<Controller/>
.Because so many of our users use Polaris, we think we should adjust our default types to work correctly with Polaris inputs. Technically speaking, this type lies -- it suppresses nulls in the output types in favour of undefineds. That said, Gadget always quacks undefined and null for these fields, so the fact that it is optional is still captured in this output type, but the exact type is not captured correctly. I think that since we can't really change Polaris, this is still the right decision so that the base case works nicely for people.
I'm super open to other ideas but I ain't got any!