[TS Migration] Improve selector and key typings for withOnyx#446
[TS Migration] Improve selector and key typings for withOnyx#446bondydaa merged 2 commits intoExpensify:mainfrom
Conversation
| 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.
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.
We are doing two things here:
- First, we omit the
TOnyxPropsfromTComponentPropsprops because, when using the HOC, we passTComponentPropsandTOnyxPropsseparately, butTComponentPropsalways 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 thiskeyfunction 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.
Thanks for the explanation!
situchan
left a comment
There was a problem hiding this comment.
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
selectorandkeyinwithOnyxHOC.Related Issues
Automated Tests
Manual Tests
Author Checklist
### Related Issuessection aboveTestssectiontoggleReportand notonIconClick)myBool && <MyComponent />.STYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)/** comment above it */thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)Avataris modified, I verified thatAvataris working as expected in all cases)mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop