Skip to content

annotate a brand's const off the value it binds, and retire the class table that guessed - #239

Merged
eburgos merged 1 commit into
masterfrom
fix/brand-annotation-off-the-value
Aug 12, 2026
Merged

annotate a brand's const off the value it binds, and retire the class table that guessed#239
eburgos merged 1 commit into
masterfrom
fix/brand-annotation-off-the-value

Conversation

@eburgos

@eburgos eburgos commented Aug 12, 2026

Copy link
Copy Markdown
Owner

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.

… 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.
@eburgos
eburgos merged commit 14441a6 into master Aug 12, 2026
@eburgos
eburgos deleted the fix/brand-annotation-off-the-value branch August 12, 2026 03:10
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.

1 participant