Skip to content

fix(type-plus)!: let a later stub.builder().with() object win - #821

Merged
unional merged 2 commits into
mainfrom
fix-stub-with-order
Oct 11, 2026
Merged

unional merged 2 commits into
mainfrom
fix-stub-with-order

Conversation

@unional

@unional unional commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • stub.builder({ a: 1 }).with({ a: 5 }).create()() returned { a: 1 }: a later .with() object only filled keys the earlier initializers left unset. It now returns { a: 5 }.
  • Precedence, now stated in the TSDoc and on the website:
    • An object initializer is deep-merged over the earlier ones, so a later .with() value wins. Nested keys it does not set are kept.
    • The partial stub passed to the call wins over every object initializer.
    • A function initializer receives the stub so far (the call-time stub merged with the initializers before it) and returns the next stub, used as is. It can override call-time values if it chooses, which keeps the existing stub.build((s) => ({ a: (s?.a ?? 0) + 1 })) behavior.
  • Implementation: each object initializer is merged over the accumulator with the paths the call-time stub sets stripped out, so a later object never overrides a call-time value, and never undoes a value an earlier function returned for a key it does not set.
  • Documented @examples are pinned in stub.builder.spec.ts / stub.build.spec.ts.
  • Includes the earlier commit giving stub.build and stub.builder their own website sections.
  • Changeset: type-plus major (8.0 is unreleased).

Verification

  • pnpm verify passes, including type tests on TS 5.4, 5.5, 5.6, 6.0 and 7, and the error snapshots.

🤖 Generated with Claude Code

unional and others added 2 commits October 10, 2026 18:26
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An object initializer now deep-merges over the earlier ones, so a later
`.with()` value wins. The partial stub passed at call time still wins over
every object initializer, and a function initializer still receives the
stub so far and returns the next one, used as is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Oct 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ae0797e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
type-plus Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov

codecov Bot commented Oct 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (9b2b94c) to head (ae0797e).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #821   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           40        40           
  Lines          173       182    +9     
  Branches        30        35    +5     
=========================================
+ Hits           173       182    +9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

@unional
unional added this pull request to the merge queue Oct 11, 2026
Merged via the queue into main with commit fd6ae1b Oct 11, 2026
7 checks passed
@unional
unional deleted the fix-stub-with-order branch October 11, 2026 01:48
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.

1 participant