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

Typescript: Omit Fetch Props from Component Props #242

Merged
merged 10 commits into from
Dec 3, 2019

Conversation

ryanbrainard
Copy link
Contributor

This pulls in @yannick-cw's change from #230.

I first committed a small example in ab96a2a to repro the problem and then applied the fix in d5ae588.

@yannick-cw, @ddanielbee: Can you take a look at the UserWidget example and let me know if this is how you were using it, particularly how I defined FetchProps and CompProps and how I passed them in as connect<FetchProps, CompProps>. It compiles and all seems to work, but just wanted to make sure I got it correct as an example.

Fixes #230

@ryanbrainard
Copy link
Contributor Author

I was just writing up readme docs how to use the TypeScript types, and I realized the whole Omit behavior is unintuitive and pretty hard to explain because the props exposed to callers are subtractive. To improve this, I tried flipping things around. Instead of connect magically omitting the fetch props, the component defines OuterProps (raw data) and InnerProps extends OuterProps (raw data + fetches). This avoids the use of Omit and uses explicit types to make it easier both for the component and caller what is expected to be passed vs what the component has access to internally. I added an explanation in the readme as well the shows an example using this pattern. Thoughts on this change?

@ryanbrainard
Copy link
Contributor Author

I just released this branch as beta react-refetch@4.0.0-0 in case anyone would like to try it out before it is merged. This is a major version because of the breaking changes for TypeScript users (no changes to the lib itself).

@ryanbrainard
Copy link
Contributor Author

Review was done in #230 (comment)

@ryanbrainard ryanbrainard merged commit b60163c into master Dec 3, 2019
@ryanbrainard ryanbrainard deleted the typescript-fixes branch December 3, 2019 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typescript types seem not to work properly
1 participant