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

feat(remix-react): add typeof action inference to useFetcher #4392

Merged
merged 3 commits into from
Oct 21, 2022

Conversation

michaelhelvey
Copy link
Contributor

@michaelhelvey michaelhelvey commented Oct 19, 2022

Closes Issue #: no official issue that I can find, but Kent mentioned in Discord that this would be a good contribution opportunity: https://discord.com/channels/770287896669978684/770287896669978687/1032333166402351154

This PR adds support for inferring the type of the .data property of useFetcher from loader and action functions, similarly to how you can write useLoaderData<typeof loader>. e.g. you can now write useFetcher<typeof action>, and fetcher.data will be inferred correctly. Previously, you had to write useFetcher<SerializeFrom<typeof action>>.

Docs:

How should this change best be documented? I struggled to find documentation for the matching changes to useActionData and useLoaderData outside of the changelog and the decisions documentation.

Testing strategy:

If there are more official "type-level" tests for this sort of thing, to automate this testing, please point me in the right direction! I pattern-matched off of the similar inference that useActionData and useLoaderData support, and couldn't find any automated tests related to the types.

  • I created a new playground by following the instructions in contributing.md
  • I noted that before the change the .data property of a fetcher (using useFetcher<typeof action>) was typed as the action function type, with no inference of the return value.
  • I noted that after the change, the return type of the above was correctly inferred as SerializeObject<UndefinedToOptional<{ /* action data */ }>> | undefined

@changeset-bot
Copy link

changeset-bot bot commented Oct 19, 2022

🦋 Changeset detected

Latest commit: 21c74e5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
remix Patch
@remix-run/react Patch
create-remix Patch
@remix-run/architect Patch
@remix-run/cloudflare Patch
@remix-run/cloudflare-pages Patch
@remix-run/cloudflare-workers Patch
@remix-run/deno Patch
@remix-run/dev Patch
@remix-run/eslint-config Patch
@remix-run/express Patch
@remix-run/netlify Patch
@remix-run/node Patch
@remix-run/serve Patch
@remix-run/server-runtime Patch
@remix-run/vercel Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@MichaelDeBoey MichaelDeBoey changed the title feat: added typeof action inference to useFetcher feat(remix-react): add typeof action inference to useFetcher Oct 20, 2022
@pcattori pcattori merged commit 75feec7 into remix-run:dev Oct 21, 2022
@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version v0.0.0-nightly-75feec7-20221022 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@MichaelDeBoey MichaelDeBoey added the awaiting release This issue has been fixed and will be released soon label Oct 22, 2022
kentcdodds pushed a commit that referenced this pull request Dec 15, 2022
* Support `typeof action` in useFetcher generic type.

* add myself to the list of contributors

* Create witty-kiwis-flow.md

Co-authored-by: Pedro Cattori <pcattori@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting release This issue has been fixed and will be released soon CLA Signed feat:typescript renderer:react
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants