Skip to content

fix(type-plus): keep ? and readonly of A in LeftJoin - #710

Merged
unional merged 2 commits into
mainfrom
fix-left-join-modifiers-205
Sep 23, 2026
Merged

unional merged 2 commits into
mainfrom
fix-left-join-modifiers-205

Conversation

@unional

@unional unional commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

Fixes #205.

Problem

LeftJoin<{ a?: number; b?: string }, { b: boolean }> returned { a: number; b: boolean }. The general branch mapped A's non-colliding keys with { [k in Exclude<keyof A, keyof B>]: A[k] }. That key set is computed, so the mapped type is not homomorphic and drops ? and readonly.

Fix

{ [k in keyof A as k extends keyof B ? never : k]: A[k] }. A key-remapping as clause over keyof A keeps the mapped type homomorphic, so A's modifiers survive.

Collision rule: when both sides declare a key, B replaces the whole property, including its ? and readonly. This matches the existing rule that B wins on the type, and it is what the B half of the join already did. The TSDoc now states the rule.

The two short-circuits (IsEqual → A, IsDisjoint → A & B) already kept modifiers. They are now covered by spec tests, so all three branches are pinned to the same behavior.

Tests

  • New spec cases in left_join.spec.ts: A's modifiers on keys B does not redeclare, B's modifiers, the collision case, and both short-circuits. The two new TSDoc @examples are pinned there.
  • The new A-modifier cases fail against the old implementation and pass with the fix.
  • test:type passes on TypeScript 5.4, 5.5, 5.6, 6.0 and 7.
  • verify:pkg, biome check and docs:llms:check pass. Error snapshots are unchanged.

Changeset: patch

I chose patch. This is a defect fix: the output now matches what a left join is expected to produce, and other type-output fixes in this release line are also patches. The package is in the 8.0.0-beta pre-release, so a larger bump would not change the version line anyway. It can still break a consumer that relied on the wrong output, for example code that read a formerly optional property as required. If the Council wants that treated as breaking, change the bump to major.

🤖 Generated with Claude Code

The general branch mapped A's non-colliding keys over
`Exclude<keyof A, keyof B>`, which is not homomorphic, so optional and
readonly modifiers were dropped. Filter with a key-remapping `as` clause
over `keyof A` instead, which keeps them. On a collision B still wins,
modifiers included.

Fixes #205

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

changeset-bot Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 96934ef

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 Patch

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 Sep 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a1fa278) to head (96934ef).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #710   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           43        43           
  Lines          231       231           
  Branches        51        51           
=========================================
  Hits           231       231           

☔ 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 enabled auto-merge September 23, 2026 08:22
@unional
unional added this pull request to the merge queue Sep 23, 2026
Merged via the queue into main with commit e996aab Sep 23, 2026
7 checks passed
@unional
unional deleted the fix-left-join-modifiers-205 branch September 23, 2026 08:26
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.

LeftJoin does not keep partial flag

1 participant