Add depth-limited type checking for discriminated unions #1711
+4,227
−4,731
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.
Discriminated unions often only need shallow validation of a discriminator field, but
typia.is<T>()validates the entire object tree. This generates excessive code and wastes runtime for what should be a simple check.Changes
New APIs
typia.isShallow<T>(input, maxDepth?)- Type guard with depth limit (default: 2)typia.createIsShallow<T>(maxDepth?)- Factory for reusable shallow validatorsImplementation
IExplore- AddeddepthandmaxDepthfields to track validation depthCheckerProgrammer.decode()- Returnstruewhendepth >= maxDepth, skipping deep validationincrementDepth()helper - Increments depth when entering nested structures (objects, arrays, tuples, maps, sets)maxDepthfrom runtime arguments, pass to programmer configExample
Depth levels:
typia.is)Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.