Skip to content

fix: Improve generic type signatures for deferred and lazy value functions - #497

Merged
nev21 merged 1 commit into
mainfrom
nev21/GenericSig
Feb 2, 2026
Merged

nev21 merged 1 commit into
mainfrom
nev21/GenericSig

Conversation

@nev21

@nev21 nev21 commented Feb 2, 2026 •

Copy link
Copy Markdown
Contributor
  • 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 nev21 added this to the 0.12.6 milestone Feb 2, 2026
@nev21
nev21 requested a review from a team as a code owner February 2, 2026 06:43
Copilot AI review requested due to automatic review settings February 2, 2026 06:43
@nev21 nev21 changed the title fix: Improve generic type signatures for deferred and lazy value func… fix: Improve generic type signatures for deferred and lazy value functions Feb 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and getWritableDeferred signatures 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 getWritableDeferred test 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.

Comment thread lib/src/helpers/cache.ts Resolved
Comment thread lib/src/helpers/lazy.ts Resolved
Comment thread lib/src/helpers/cache.ts Resolved
@codecov

codecov Bot commented Feb 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.89%. Comparing base (565203b) to head (d85ff12).
⚠️ Report is 1 commits behind head on main.

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           
Files with missing lines Coverage Δ
lib/src/helpers/cache.ts 100.00% <100.00%> (ø)
lib/src/helpers/lazy.ts 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@nev21
nev21 enabled auto-merge (squash) February 2, 2026 16:34
@nev21
nev21 disabled auto-merge February 2, 2026 16:37
@nev21
nev21 merged commit d3886de into main Feb 2, 2026
18 checks passed
@nev21
nev21 deleted the nev21/GenericSig branch 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants