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-server-runtime): MetaFunction type infers data and parentsData types from loaders #4022

Merged

Conversation

pcattori
Copy link
Contributor

@pcattori pcattori commented Aug 19, 2022

Supercedes #928

See usage example in new jsdoc for MetaFunction or in the changeset

  • Docs
  • Tests

Testing Strategy: I tried out the example shown in the jsdoc locally

@changeset-bot
Copy link

changeset-bot bot commented Aug 19, 2022

🦋 Changeset detected

Latest commit: 591895a

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

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

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

Comment on lines +137 to +142
data: Loader extends LoaderFunction ? SerializeFrom<Loader> : AppData;
parentsData: {
[k in keyof ParentsLoaders]: SerializeFrom<ParentsLoaders[k]>;
} & RouteData;
Copy link
Contributor Author

@pcattori pcattori Aug 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppData and RouteData included for backwards compatibility. In v2, we should change AppData to unknown and remove the need for AppData and RouteData here:

// In Remix v2:
export interface MetaFunction<
  Loader extends LoaderFunction,
  ParentsLoaders extends Record<string, LoaderFunction> = {}
> {
  (args: {
    data: SerializeFrom<Loader>;
    parentsData: {
      [k in keyof ParentsLoaders]: SerializeFrom<ParentsLoaders[k]>;
    };
   ...

@pcattori pcattori marked this pull request as ready for review August 19, 2022 15:21
@pcattori pcattori changed the title feat: metafunction type can now infer data and parentsData types … feat: metafunction type can now infer data and parentsData types from loaders Aug 19, 2022
@pcattori pcattori requested a review from chaance August 19, 2022 15:27
@pcattori pcattori changed the title feat: metafunction type can now infer data and parentsData types from loaders feat: MetaFunction type infers data and parentsData types from loaders Aug 19, 2022
@pcattori pcattori force-pushed the pedro/infer-metafunction-data-and-parentsdata-from-loaders branch from 8a46f3d to 60b10a3 Compare August 19, 2022 16:17
Copy link
Collaborator

@chaance chaance left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Since this is technically new API, wanna get one more set of eyes before merging?

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Holy crap I love this 👍

@kentcdodds
Copy link
Member

@pcattori could you add some docs on this in the MetaFunction docs?

@pcattori pcattori force-pushed the pedro/infer-metafunction-data-and-parentsdata-from-loaders branch from 60b10a3 to 591895a Compare August 19, 2022 17:56
@pcattori pcattori merged commit f793b61 into dev Aug 19, 2022
@pcattori pcattori deleted the pedro/infer-metafunction-data-and-parentsdata-from-loaders branch August 19, 2022 18:10
@MichaelDeBoey MichaelDeBoey changed the title feat: MetaFunction type infers data and parentsData types from loaders feat(remix-server-runtime): MetaFunction type infers data and parentsData types from loaders Aug 20, 2022
@MichaelDeBoey MichaelDeBoey added docs package:server-runtime awaiting release This issue has been fixed and will be released soon labels Aug 20, 2022
@MichaelDeBoey MichaelDeBoey removed the awaiting release This issue has been fixed and will be released soon label Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants