-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Infer HoC props #805
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
Infer HoC props #805
Conversation
I'm not going to pretend to understand the TS intricacies that let this work but I love the sight of all those - export default withAppProvider<Props>()(Thing);
+ export default withAppProvider()(Thing); changes! |
2eae288
to
776f8e5
Compare
Updated types Format Fix withSticky
776f8e5
to
0a1ae9e
Compare
👀 |
export default function withAppProvider<OwnProps>() { | ||
return function addProvider<C>( | ||
export default function withAppProvider() { | ||
return function addProvider<OriginalProps, C>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C is Context in this case correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it's for inferring the typeof component. So for example
withSticky()(Scrollable);
will infer React.ComponentClass<Props, React.ComponentState> & typeof Scrollable
. typeof Scrollable
will be inferred from & C
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great. What version of Typescript made this possible?
I couldn't build-consumer because of icons to test on web. I can't see see the resulting build impacting web but going with lessons learned.
Not sure
I think it'll be best to wait as well, until we can 🎩 in web |
Steps to 🎩 in webYou'll want to be on master in
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tophatted in web
and tested all components in the style guide as well. All are 💯
WHY are these changes introduced?
Improved HoC usage
WHAT is this pull request doing?
Letting typescript infer props rather than passing them as generics
Old
New
When we compose HoC we'll still have to pass props but only to compose
Old
New
How to 🎩
This is a pretty big change so we'll want to test the components making use of different HoC.
Here's small list of some components you'll want to test making use of some HoC's
withSticky
withAppProvider
withContext
withRef