Skip to content

feat: allow string enums for errors#345

Merged
darshkpatel merged 3 commits intomainfrom
allow-string-enum-error-codes
Oct 20, 2025
Merged

feat: allow string enums for errors#345
darshkpatel merged 3 commits intomainfrom
allow-string-enum-error-codes

Conversation

@darshkpatel
Copy link
Contributor

@darshkpatel darshkpatel commented Oct 20, 2025

Why

to provide better type safety and developer experience when defining error schemas.

What changed

  • Added support for TypeScript enums as valid error code types in the BaseErrorSchemaType
  • Updated the Flatten type helper to properly handle unions containing enum-based error schemas
  • Tests

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

Allow string enums for error code in router/errors.ts to support the purpose stated in the PR title

This change updates error schema typing to accept string enums in addition to string literals and extends tests to cover enum-based error codes and unions. It modifies BaseErrorSchemaType and union flattening logic and adds test coverage for enum-based error schemas in the TypeScript stress suite.

  • Update BaseErrorSchemaType in router/errors.ts so code accepts TEnum via a new TStringCode type
  • Adjust Flatten<T> union handling in router/errors.ts to return TUnion<Array<U>> when U extends BaseErrorSchemaType
  • Add TestErrorCodes enum and expand allowed error schema cases in tests/typescript-stress.test.ts to include enum-based schemas, mixed unions, and flattenErrorType with nested unions

📍Where to Start

Start with the updated BaseErrorSchemaType and TStringCode definitions in router/errors.ts, then review the Flatten<T> conditional type changes before verifying coverage in tests/typescript-stress.test.ts.


📊 Macroscope summarized ddef0bf. 1 files reviewed, 0 issues evaluated, 0 issues filtered, 0 comments posted

🗂️ Filtered Issues

No issues evaluated.

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

macroscopeapp bot commented Oct 20, 2025

Accept string enums for error code fields in router/errors.ts to allow string enum-based error schemas

This change updates the error schema typing to accept string enums for the code property and adjusts union flattening behavior, with accompanying tests and a version bump. • Modify BaseErrorSchemaType in router/errors.ts to use a new TStringCode type that includes TLiteral<string> and TEnum, and update Flatten<T> to preserve unions of BaseErrorSchemaType as TUnion<Array<U>> while continuing recursive flattening for other members. • Add tests in tests/typescript-stress.test.ts validating Type.Enum-based error codes, unions combining enum-based schemas, and flattenErrorType with unions containing enum-based schemas. • Bump package version from 0.209.8 to 0.210.0 in package.json.

📍Where to Start

Start with the updated BaseErrorSchemaType and TStringCode definitions and the Flatten<T> conditional logic in router/errors.ts.

Changes since #345 opened

  • Refactored error code type system by replacing unified string code type with separate string enum and literal types [05466f9]

📊 Macroscope summarized 05466f9. 1 files reviewed, 0 issues evaluated, 0 issues filtered, 0 comments posted

🗂️ Filtered Issues

No issues evaluated.

@darshkpatel darshkpatel force-pushed the allow-string-enum-error-codes branch from ddef0bf to 9be223a Compare October 20, 2025 00:14
@darshkpatel darshkpatel requested a review from jackyzha0 October 20, 2025 00:15
Copy link
Contributor

@daweifeng-replit daweifeng-replit left a comment

Choose a reason for hiding this comment

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

Cool! I should start using enum too!

@darshkpatel darshkpatel merged commit ab974ca into main Oct 20, 2025
10 checks passed
@darshkpatel darshkpatel deleted the allow-string-enum-error-codes branch October 20, 2025 00:31
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