Add parseSafe and parseStrict cases for @sinclair/typebox - #2333
Open
colinhacks wants to merge 2 commits into
Open
Add parseSafe and parseStrict cases for @sinclair/typebox#2333colinhacks wants to merge 2 commits into
colinhacks wants to merge 2 commits into
Conversation
colinhacks
force-pushed
the
typebox-parse-categories
branch
from
August 30, 2026 23:51
85a480f to
ef55d5f
Compare
moltar
requested changes
Aug 31, 2026
| if (!Value.Check(Loose, data)) { | ||
| throw new Error('validation failure'); | ||
| } | ||
| return Value.Clean(Loose, Value.Clone(data)) as typeof data; |
Owner
There was a problem hiding this comment.
That's cheating! Cannot accept it. 😁
Contributor
Author
There was a problem hiding this comment.
Fair! Reworked it to use Value.Parse — TypeBox's first-class parse entry point, which clones, strips unknown keys, and asserts in one call and returns a typed result. The just-in-time variant drops parseSafe entirely, since TypeCompiler only compiles checks and has no parse pipeline.
One thing worth knowing: the default Value.Parse pipeline includes Convert, so it coerces e.g. string numbers the way yup's non-strict validateSync does. The category tests pass either way.
| if (!CheckLoose.Check(data)) { | ||
| throw new Error('validation failure'); | ||
| } | ||
| return Value.Clean(Loose, Value.Clone(data)) as typeof data; |
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.
The @sinclair/typebox cases currently register only the assert categories. This adds parseSafe and parseStrict to the dynamic and just-in-time variants.
For parseSafe, TypeCompiler only compiles the check, so unknown-key removal goes through the dynamic Value module: Check first, then
Value.Cleanon aValue.Cloneso the input is not mutated and the case returns a new object. parseStrict checks against the Strict schema and returns the input, matching the typia case.The ahead-of-time variant is left as-is — its generated modules contain only check functions, and a parse case there would measure the same dynamic Clean.