Skip to content

fix: recursive flattening for nested error unions#347

Merged
darshkpatel merged 3 commits intomainfrom
10-20-fix_recursive_flattening_for_nested_error_unions
Oct 20, 2025
Merged

fix: recursive flattening for nested error unions#347
darshkpatel merged 3 commits intomainfrom
10-20-fix_recursive_flattening_for_nested_error_unions

Conversation

@darshkpatel
Copy link
Contributor

@darshkpatel darshkpatel commented Oct 20, 2025

Why

Fixed a bug in the flattenErrorType utility where spreading a flattened union into another union was not working as expected.

What changed

  • Fixed the Flatten type in router/errors.ts to properly handle nested unions (again)
  • Added a test case that demonstrates spreading a flattened union into another union
  • Bumped package version from 0.210.0 to 0.210.1

Versioning

  • Breaking protocol change
  • Breaking ts/js API change

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@macroscopeapp
Copy link

macroscopeapp bot commented Oct 20, 2025

Fix recursive flattening for nested error unions in errors.Flatten to correct union handling for error schema composition

This change updates the TypeScript type-level flattening logic for error unions and adds a test to cover composing flattened error schemas within nested unions. It also increments the package version and updates the lockfile.

  • Modify the errors.Flatten generic type to always recurse into TUnion<Array<infer U>> using Flatten<U>, add a branch to return T when T directly extends TUnion, and export the alias in router/errors.ts
  • Add a test case validating acceptance of a flattened base error schema combined with an additional error object via Type.Union in tests/typescript-stress.test.ts
  • Bump version from 0.210.0 to 0.210.1 in package.json
  • Update generated metadata in package-lock.json

📍Where to Start

Start with the updated errors.Flatten type in router/errors.ts to review the revised recursion and union handling, then verify behavior with the new test in tests/typescript-stress.test.ts.

Changes since #347 opened

  • Modified the Flatten generic type alias to remove conditional branch and implement recursive flattening for nested error unions [b139b29]
  • Refactored error schema construction in procedure error schema test case [b139b29]

Macroscope summarized b139b29.

@darshkpatel darshkpatel requested a review from Monkatraz October 20, 2025 18:40
@darshkpatel darshkpatel marked this pull request as ready for review October 20, 2025 18:40
@darshkpatel darshkpatel requested a review from a team as a code owner October 20, 2025 18:40
@darshkpatel darshkpatel requested review from daweifeng-replit and removed request for a team October 20, 2025 18:40
Copy link
Member

@jackyzha0 jackyzha0 left a comment

Choose a reason for hiding this comment

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

Image

@darshkpatel darshkpatel merged commit 7ce5281 into main Oct 20, 2025
10 checks passed
@darshkpatel darshkpatel deleted the 10-20-fix_recursive_flattening_for_nested_error_unions branch October 20, 2025 19:00
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.

3 participants