Repository navigation
fix: Improve generic type signatures for deferred and lazy value functions - #497
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refines the generic type signatures for the lazy and deferred helper functions to improve flexibility and type inference, and updates the associated tests to validate the new behavior.
Changes:
- Updated
getLazy,getWritableLazy,getDeferred, andgetWritableDeferredsignatures to use more flexible callback typings (including a union callback type and adjusted generic defaults). - Adjusted lazy helper tests to cover complex argument scenarios under the new typings.
- Relaxed some
getWritableDeferredtest typings to keep runtime behavior tests compiling with the updated generics.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
lib/src/helpers/lazy.ts |
Updates getLazy and getWritableLazy callback and generic signatures to support more flexible argument patterns while preserving lazy evaluation behavior. |
lib/src/helpers/cache.ts |
Adjusts getDeferred and getWritableDeferred callback signatures and defaults to better align with lazy helpers and support argument arrays; keeps runtime caching semantics the same. |
lib/test/src/common/helpers/lazy.test.ts |
Modifies lazy helper tests, especially for complex and function arguments, to validate the updated callback typing and argument handling. |
lib/test/src/common/helpers/cache.test.ts |
Tweaks getWritableDeferred tests, including object/array/safe-function scenarios, to remain compatible with the new generic signatures and ensure deferred caching behavior is still correct. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #497 +/- ##
=======================================
Coverage 98.89% 98.89%
=======================================
Files 108 108
Lines 2981 2981
Branches 645 645
=======================================
Hits 2948 2948
Misses 33 33
🚀 New features to boost your workflow:
|
…tions - Update getLazy and getWritableLazy to use more flexible callback type signature - Add union type to callback parameters: `cb: F | ((...args: any[]) => T)` - Align type parameter defaults with getDeferred pattern for consistency This improves type inference and allows more flexible usage patterns when passing callbacks with arguments to deferred/lazy value creation functions.
nev21
force-pushed
the
nev21/GenericSig
branch
from
February 2, 2026 08:00
9335882 to
d85ff12
Compare
nev21
enabled auto-merge (squash)
February 2, 2026 16:34
nev21
disabled auto-merge
February 2, 2026 16:37
nev21
added a commit
that referenced
this pull request
Feb 2, 2026
- Update safe() to use ReturnType<F> instead of any for better type inference - Align safeGet, safeGetLazy, safeGetWritableLazy, safeGetDeferred, and safeGetWritableDeferred with the same flexible callback signature pattern - Change default type parameter from () => T to (...args: any[]) => T - Add union type to callback parameters: cb: F | ((...args: Parameters<F>) => T) - Remove unnecessary default (T = boolean) from safeGet - Fix typo in safeGetWritableLazy documentation Extends the type flexibility improvements from #497 to all safe wrapper functions for consistent API patterns and better type inference across the library.
nev21
added a commit
that referenced
this pull request
Feb 3, 2026
- Update safe() to use ReturnType<F> instead of any for better type inference - Align safeGet, safeGetLazy, safeGetWritableLazy, safeGetDeferred, and safeGetWritableDeferred with the same flexible callback signature pattern - Change default type parameter from () => T to (...args: any[]) => T - Add union type to callback parameters: cb: F | ((...args: Parameters<F>) => T) - Remove unnecessary default (T = boolean) from safeGet - Fix typo in safeGetWritableLazy documentation Extends the type flexibility improvements from #497 to all safe wrapper functions for consistent API patterns and better type inference across the library.
nev21
added a commit
that referenced
this pull request
Feb 3, 2026
…498) - Update safe() to use ReturnType<F> instead of any for better type inference - Align safeGet, safeGetLazy, safeGetWritableLazy, safeGetDeferred, and safeGetWritableDeferred with the same flexible callback signature pattern - Change default type parameter from () => T to (...args: any[]) => T - Add union type to callback parameters: cb: F | ((...args: Parameters<F>) => T) - Remove unnecessary default (T = boolean) from safeGet - Fix typo in safeGetWritableLazy documentation Extends the type flexibility improvements from #497 to all safe wrapper functions for consistent API patterns and better type inference across the library.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cb: F | ((...args: any[]) => T)This improves type inference and allows more flexible usage patterns when passing callbacks with arguments to deferred/lazy value creation functions.