-
Notifications
You must be signed in to change notification settings - Fork 74
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
[TS Migration] Improve selector and key typings for withOnyx #446
[TS Migration] Improve selector and key typings for withOnyx #446
Conversation
@@ -42,7 +42,7 @@ type EntryBaseMapping<TOnyxKey extends OnyxKey> = { | |||
*/ | |||
type BaseMappingKey<TComponentProps, TOnyxProps, TOnyxProp extends keyof TOnyxProps, TOnyxKey extends OnyxKey, TOnyxValue> = IsEqual<TOnyxValue, TOnyxProps[TOnyxProp]> extends true | |||
? { | |||
key: TOnyxKey | ((props: Omit<TComponentProps, keyof TOnyxProps>) => TOnyxKey); | |||
key: TOnyxKey | ((props: Omit<TComponentProps, keyof TOnyxProps> & Partial<TOnyxProps>) => TOnyxKey); |
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.
Why is this better (or different) than TComponentProps & TOnyxProps
? It appears to me like this is omitting properties, and then adding them right back with an intersection.
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.
We are doing two things here:
- First, we omit the
TOnyxProps
fromTComponentProps
props because, when using the HOC, we passTComponentProps
andTOnyxProps
separately, butTComponentProps
always have all the props fromTOnyxProps
. - Now with that, we make a union with
Partial<TOnyxProps>
to make the Onyx props optional, because as @blazejkustra correctly pointed out the Onyx props are not available in thiskey
function during the first render.
We can't do TComponentProps & Partial<TOnyxProps>
directly because as TComponentProps
has TOnyxProps
props, making a union with Partial<TOnyxProps>
won't make them optional.
In fact, if it weren't by the optional Onyx props, we could just do TComponentProps
because TComponentProps
always has all Onyx props from TOnyxProps
. Here is an example.
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.
Thanks for the explanation!
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.
does this repo require reviewer checklist?
No, there is no checklist for the repo. I'm not exactly sure why @bondydaa added you :D When the PR is made to NewDot to update this library version, it should get a C+ review then (with the regular checklist). |
If you want to review this, that's perfectly fine, but feel free to pass and I will just merge this now. Let me know what you prefer. |
Please feel free to merge (I already reviewed and approved). |
Yeah sorry! I didn't realize this was the onyx repo before asking and then assigning. |
Details
This PR fixes and improves typings for
selector
andkey
inwithOnyx
HOC.Related Issues
Automated Tests
Manual Tests
Author Checklist
### Related Issues
section aboveTests
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
this
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop