feat/tschema improvements#68
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR enhances the TSchema module with new Literal options for better Union control, simplifies implementation by removing redundant code, and adds comprehensive test coverage.
Key Changes
- Added
LiteralOptionsinterface withindexandflatInUnionoptions for custom positioning and flattening behavior in unions - Removed redundant
OneLiteralfunction, consolidating into the mainLiteralfunction with overloaded signatures - Optimized collision detection algorithm from O(n²) to O(n) using Map-based tracking
- Added 7 new round-trip tests covering UndefinedOr, custom indices, flatFields, Variant, TaggedStruct, and flatInUnion combinations
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/evolution/src/core/TSchema.ts | Core implementation changes: simplified helper functions, added Literal options, removed OneLiteral, optimized Union collision detection, and improved error handling |
| packages/evolution/test/TSchema.test.ts | Added 7 new comprehensive round-trip tests for previously untested features including UndefinedOr, custom indices, flatFields, Variant, and TaggedStruct |
| packages/evolution/docs/modules/core/TSchema.ts.md | Updated documentation to reflect OneLiteral removal, added LiteralOptions interface documentation, and updated TaggedStruct signature |
| .changeset/beige-donuts-wish.md | Detailed changeset documenting new features, code simplifications, optimizations, and new test coverage |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ? String(actual) | ||
| : JSON.stringify(actual) | ||
| const actualType = getTypeName(actual) | ||
| const actualStr = typeof actual === "object" ? String(actual) : JSON.stringify(actual) |
There was a problem hiding this comment.
The actualStr calculation doesn't handle bigints correctly. When actual is a bigint, typeof actual === "object" is false, so it will try JSON.stringify(actual), which throws an error because JSON.stringify cannot serialize bigints.
Consider using the same pattern as getTypeName to handle all types consistently:
const actualStr = typeof actual === "bigint" ? String(actual) : typeof actual === "object" ? String(actual) : JSON.stringify(actual)
Suggested change
| const actualStr = typeof actual === "object" ? String(actual) : JSON.stringify(actual) | |
| const actualStr = typeof actual === "bigint" | |
| ? String(actual) | |
| : typeof actual === "object" | |
| ? String(actual) | |
| : JSON.stringify(actual) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.