-
Notifications
You must be signed in to change notification settings - Fork 83
Refactor OnyxUpdate type to bring back type safety #696
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
base: main
Are you sure you want to change the base?
Conversation
| type Collection<TKey extends CollectionKeyBase, TValue, TMap = never> = { | ||
| [MapK in keyof TMap]: MapK extends `${TKey}${string}` | ||
| ? MapK extends `${TKey}` | ||
| ? never // forbids empty id | ||
| : TValue | ||
| : never; | ||
| }; |
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 wasn't working as expected, so needed to refactor this a bit @fabioh8010.
Which caused a lot of type errors in tests and lib catalogs
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.
Did some testing on E/App and looks okay I think 👌
| @@ -1,5 +1,4 @@ | |||
| import type {Merge} from 'type-fest'; | |||
| import type {BuiltIns} from 'type-fest/source/internal'; | |||
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 not a stable api in type-fest, it was actually moved to another file in next type-fest major version which can lead to a lot of silent type errors in projects using react-native-onyx.
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / SafariMacOS: Desktop |
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.
Tests all working as expected. LGTM.
| type Collection<TKey extends CollectionKeyBase, TValue, TMap = never> = { | ||
| [MapK in keyof TMap]: MapK extends `${TKey}${string}` | ||
| ? MapK extends `${TKey}` | ||
| ? never // forbids empty id | ||
| : TValue | ||
| : never; | ||
| }; |
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.
Did some testing on E/App and looks okay I think 👌
Details
This PR fixes the
OnyxUpdatestype. Specifically, thevalueproperty of an update was not type-safe because the key was incorrectly inferred.It also introduces type tests, which can be expanded and refined in the future.
diston the fly) since augmenting the type definitions was affecting the entirelibcatalog:Would you like me to make it slightly more formal or concise (e.g. for a PR description or commit message)?
Related Issues
Expensify/App#73830
Automated Tests
N/A
Manual Tests
N/A
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