Refactor OnyxUpdate type to support generics for improved performance#703
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.
@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.
Nice, and Intelissense looks faster now 🎉
|
outside of tests, this is a type-only PR, so I'm going to ignore reassure which is surely a false positive |

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