Skip to content
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

Strip nulls from the form state type for maximum polaris compatability #699

Commits on Nov 22, 2024

  1. Strip nulls from the form state type for maximum polaris compatability

    Shopify Polaris, in its infinite wisdom, accepts only `string | undefined` for the `value` prop on its `<TextInput/>` component. `<input/>` in the DOM accepts `string | readonly string[] | number | undefined;`, which you'd think Polaris would be ok with, but alas no. At runtime, it's absolutely fine to pass `null` to the TextInput, it works fine, it's just the type that is not ok with it. Because Gadget's API responds with `null`, not `undefined` for fields that haven't been set yet, it means that the form values type have `string | 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.
    airhorns committed Nov 22, 2024
    Configuration menu
    Copy the full SHA
    73a84bb View commit details
    Browse the repository at this point in the history