annotate a brand's const off the value it binds, and retire the class table that guessed - #239
Merged
Merged
Conversation
… table that guessed
A brand's published const named its own Zod class — `$ZodBranded<ZodString,
"Stamp">` — read off a table keyed by the inner's rendered name. The table was
wrong twice over. Where it missed, tsc refused the module outright: a chrono
inner binds a date coercer, not a string schema, and the fallthrough said
`ZodString` anyway — eight hard errors across the chrono brands, the
instantiated path and the generic default. Where it hit, six of sixteen brands
type-checked while silently widening what `.parse()` infers: a `Vec` inner
became `unknown[]`, a map became `Record<string | number | symbol, unknown>`,
an `ObjectId` a bare string record, and a brand over a brand dropped the inner
mark.
The annotation now reads off the value instead of naming its class:
export const Stamp$Schema: typeof Stamp$RawSchema = Stamp$RawSchema;
the same spelling a republished binding already carries, and exact by
construction whatever the inner is — the chrono brands infer their real `Date`,
the composites keep their element types, and a brand over a brand keeps both
marks. Being exact by naming classes would have meant restating zod's type
algebra in Rust, arm by arm, forever.
The table and everything that served it are deleted: the class-name dispatch,
its instantiated and default-argument readers, and both enums. Its one
surviving question — is the inner a composite — became a predicate on the JSON
gate that asks it. `$ZodBranded` no longer appears in the emission at all, and
a consumer's preamble needs only `z`, `ZodType`, and `$brand`.
Measured on the crate's own emission: eight TS2322s to zero, declaration emit
clean, and every one of twenty brands inferring exactly, where fourteen did
before. Runtime parse and brand behaviour byte-identical.
just fmt, just check, just quick, just lint-all across all 68 toggles, and the
test powerset across all 68 in four partitions — all green.
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.
A brand's published const named its own Zod class —
$ZodBranded<ZodString, "Stamp">— read off a table keyed by the inner's rendered name. The table waswrong twice over. Where it missed, tsc refused the module outright: a chrono
inner binds a date coercer, not a string schema, and the fallthrough said
ZodStringanyway — eight hard errors across the chrono brands, theinstantiated path and the generic default. Where it hit, six of sixteen brands
type-checked while silently widening what
.parse()infers: aVecinnerbecame
unknown[], a map becameRecord<string | number | symbol, unknown>,an
ObjectIda bare string record, and a brand over a brand dropped the innermark.
The annotation now reads off the value instead of naming its class:
the same spelling a republished binding already carries, and exact by
construction whatever the inner is — the chrono brands infer their real
Date,the composites keep their element types, and a brand over a brand keeps both
marks. Being exact by naming classes would have meant restating zod's type
algebra in Rust, arm by arm, forever.
The table and everything that served it are deleted: the class-name dispatch,
its instantiated and default-argument readers, and both enums. Its one
surviving question — is the inner a composite — became a predicate on the JSON
gate that asks it.
$ZodBrandedno longer appears in the emission at all, anda consumer's preamble needs only
z,ZodType, and$brand.Measured on the crate's own emission: eight TS2322s to zero, declaration emit
clean, and every one of twenty brands inferring exactly, where fourteen did
before. Runtime parse and brand behaviour byte-identical.
just fmt, just check, just quick, just lint-all across all 68 toggles, and the
test powerset across all 68 in four partitions — all green.