-
Notifications
You must be signed in to change notification settings - Fork 84
[WIP] Refactor OnyxUpdate type to support generics for improved performance #703
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
|
@fabioh8010 @roryabraham All yours 😄 |
|
After testing in the repo I noticed few edge cases, let's hold with reviews for now. |
Is it ready to review now @blazejkustra ? |
|
Yes @fabioh8010 🙌 |
fabioh8010
left a comment
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.
@blazejkustra Looks like Onyx.update() is not being able to recognise Onyx.METHOD.SET_COLLECTION and Onyx.METHOD.MERGE_COLLECTION methods.
FYI I'm still working on this, basically Onyx.update doesn't narrow the type correctly. Why is this so hard to type 😭 |
|
NAB suggestion: Implement some type-tests in the manner of type-fest. We had a type regression on this code once before... |
|
I initially introduced const onyxUpdateCollectionMember: OnyxUpdate<typeof ONYX_KEYS.COLLECTION.TEST_KEY> = {
onyxMethod: 'set',
key: `${ONYX_KEYS.COLLECTION.TEST_KEY}1`,
value: {
str: 'test1',
},
};instead of this complex type: const onyxUpdateCollectionMember: OnyxUpdate<`${typeof ONYX_KEYS.COLLECTION.TEST_KEY}${string}`> = {
...
};I realized that narrowing completely broke because of this type.
|
|
I made this PR draft again since I'm OOO 20-26 Nov. The PR is ready to review but I don't think merging is a good idea as it could block other updates in onyx while I'm gone. |
fabioh8010
left a comment
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.
Nice, and Intelissense looks faster now 🎉

Details
After fixing type safety of OnyxUpdate we observed a massive TS slowdown due to complexity of this type, in order to improve it we decided to make it a generic so it doesn't produce huge union types of objects that are making TS and ESlint slow.
Relevant discussion: https://expensify.slack.com/archives/C01GTK53T8Q/p1762617983543509
Related Issues
Expensify/App#73830
Automated Tests
N/A
Manual Tests
N/A (purely type change)
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
N/A