-
Notifications
You must be signed in to change notification settings - Fork 82
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
Refactor OnyxUpdate type to bring back type safety #696
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 👌
…x/update-typesafety
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.
NAB, LGTM!
|
@chrispader can you also review please? |
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.
LGTM, i just requested some additional comments, but not a blocker!
|
Do i understand correctly, that the approach with the type tests is to make sure, that whenever we change the types and it creates type errors that were not explicitly ignored with In this case, how do we prevent from introducing other type errors for the same lines for which currently errors are ignored/expected? Currently, these might slip through, right? |
Yes!
Yes, but it's better than nothing 😄 And in most cases the errors would be caused in other places too, so it would be easily visible. |
|
All yours @MarioExpensify |
|
@MarioExpensify All yours 🙌 |
|
On it! |
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 really good! Thank you! LGTM
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: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