-
Notifications
You must be signed in to change notification settings - Fork 39
feat(atomic): Add support for return types in the once util function #6684
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
Conversation
9a5c947 to
9ec0939
Compare
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.
Pull request overview
This pull request enhances the once utility function by adding TypeScript generic support for return types, improving type inference when wrapping functions. The changes enable better type safety and developer experience by allowing TypeScript to infer the return type of the wrapped function.
Key Changes
- Added generic type parameter
Rto capture and preserve the return type of wrapped functions - Changed the memoization flag from setting
fn = () => {}tofn = nullto enable garbage collection of the original function reference - Added comprehensive test coverage for different function signatures (with arguments, void functions, and typed functions)
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/atomic/src/utils/utils.ts | Updated once function signature with generic return type parameter and changed memoization implementation to null out function reference for garbage collection |
| packages/atomic/src/utils/utils.spec.ts | Added four new test cases covering argument handling, memoization behavior, void functions, and type inference |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: lavoiesl <1216046+lavoiesl@users.noreply.github.com>
https://coveord.atlassian.net/browse/KIT-5270