Repository navigation
fix(codegen): TS7056 post-processor emits typed z.ZodType<T, T> - #1924
Merged
Merged
Conversation
The Zod-from-TS post-processor annotates schemas that hit TypeScript's
.d.ts serialization limit (TS7056) so the compiler stops trying to
serialize the inferred shape. The previous bare z.ZodType annotation
made z.input<typeof X> resolve to `unknown` — breaking
AdcpToolMap[K]['params'] narrowing for any annotated request schema.
Changes:
- TS7056_SCHEMAS entries now carry an optional `tsType`. When present,
the annotation uses the 2-type-param Zod v4 form
`z.ZodType<T, T>` with `& Record<string, unknown>` widening to
reflect runtime passthrough() semantics. z.input<...> resolves
correctly; downstream destructures keep field types.
- Auto-inject `import type { ... } from './tools.generated'` for the
typed annotations.
- Pre-emptively annotate 5 schemas that hit TS7056 on 3.1.0-beta.2
(PreviewCreativeRequest, UpdateMediaBuyRequest/Response,
BuildCreativeResponse, SyncEventSourcesResponse). Annotation is
harmless on the current 3.0.12 pin.
- One-line cast at the withOptionalAccount(UpdateMediaBuyRequestSchema)
call site so the helper's z.ZodObject<...> constraint is satisfied
after annotation widening. Runtime shape unchanged.
Why pre-emptive: the 8.0-beta cut (#1902) needs this codegen behavior
to compile its dist/. Landing on main decouples it from the 8.0-beta
foundation stack.
Patch bump — purely codegen tooling; no wire change; no API change.
Contributor
There was a problem hiding this comment.
LGTM. Codegen fix; the new annotation makes z.input<typeof X> resolve to the typed shape instead of unknown, which is what the AdcpToolMap narrowing depends on. Follow-ups noted below.
Things I checked
- Regex
export const ${name} =inpostProcessTS7056Annotationscannot false-match: each affected schema name is uniquely terminated bySchema =and no sibling export shares the prefix at the right boundary (scripts/generate-zod-from-ts.ts:95). - Cast site at
tool-request-schemas.ts:34is runtime-safe —UpdateMediaBuyRequestSchemais stillz.object(...).passthrough()at runtime, sowithOptionalAccount's.shape.account.optional()+.extend(...)still hits a real ZodObject. The annotation widening is type-only. & Record<string, unknown>widening distributes correctly overz.union(...)annotations (UpdateMediaBuyResponseSchema, BuildCreativeResponseSchema, SyncEventSourcesResponseSchema).z.input<typeof X>resolves toX & Record<string, unknown>on each union member. No callerz.infers these schemas today, so the widening is invisible downstream.version.ts7.10.1 → 7.10.2 is drift correction, not a manual bump.package.jsononorigin/mainis already at 7.10.2 (Release PR #1923) butversion.tswas left at 7.10.1 — sync-version output now matches. Next Release PR will carry both to 7.10.3 together.- Patch changeset present, type matches impact (codegen-tooling, no wire/API change).
Follow-ups (non-blocking — file as issues)
- Missing fail-fast guard on the import-injection step.
scripts/generate-zod-from-ts.ts:130doesresult.replace(/import { z } from "zod";\n/, ...). If ts-to-zod ever changes its import shape (single quotes, combined import, no trailing newline), the replace silently no-ops and you get a downstream TS error about unresolvedPreviewCreativeRequest. The sibling guards in this file (lines 96-100, 152-157) fail loudly with a named error — this one should too. Assert the import landed whentypesToImport.length > 0. - Dead
objectShapeinfrastructure. The script's type signature and theif (objectShape)branch at lines 78 and 115 are unreachable today — no entry sets the flag. Either delete it, or leave a one-line comment naming the worked example a future entry would use it for. As-shipped a future reader has to spelunk to understand what it's for.
Minor nits (non-blocking)
- Three JSDoc blocks above one constant (scripts/generate-zod-from-ts.ts:49-57, 58-69, 70-77). Only the last binds; the first two are dangling. Collapse into one. Notable — even codegen tolerates two.
- Cast helper. If a second TS7056-driven cast lands,
as unknown as z.ZodObject<z.ZodRawShape>will get reinvented with a fresh comment. Hoisting a one-linerasZodObject(s)helper nearwithOptionalAccountkeeps the workaround in one place.
Safe to merge.
bokelley
added a commit
that referenced
this pull request
May 22, 2026
…al sweep) Foundation rebased onto main. Picks up: - Pre-mode entry (#1933) so foundation publishes under @beta - Codegen TS7056 fix (#1924) - Wholesale-feed-sync rename (#1932, replaces catalog-sync from earlier branch) - 3.1.0-beta.3 schema bundle (was beta.2 on the foundation branch) Resolutions: - .changeset/pre.json: took main's (initialVersions=8.0.0) - src/lib/version.ts: regenerated via sync-version --force - src/lib/types/schemas.generated.ts: regenerated - ADCP_VERSION: bumped 3.1.0-beta.2 → 3.1.0-beta.3 Demoted foundation changeset major → minor so the foundation merge publishes as 8.1.0-beta.0 (stays on 8.x line). The 9.0 major bump can come when v1 deprecation calendar tightens, not from this cut. Beta.3 spec changes folded in (partial): - RETENTION_EXPIRED removed from ErrorCodeValues; STALE_RESPONSE added. Updated DEFAULT_CODE_POLICY accordingly. - Envelope `status` REQUIRED on all responses — added 'failed' to two synthetic-error envelopes in response-unwrapper.ts. - ControllerError / SeedSuccess / wrapped store returns updated to carry envelope `status` (introduced wrapStoreSuccess helper in src/lib/server/test-controller.ts). - Type guards in src/lib/testing/test-controller.ts widened to handle the new union shape with envelope intersection. KNOWN ISSUE: ~45 more compile errors remain across decisioning/ adapter/middleware code from the envelope-status-required change. Each is mechanical (add `status: 'completed'` to a success-shape return) but the sweep is wider than this single merge commit. Pushed for visibility; follow-up PRs will sweep the remainder.
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.
Targeting `main` directly — purely codegen-tooling, no wire/API change. Patch bump.
Problem
The Zod-from-TS post-processor (`scripts/generate-zod-from-ts.ts`) annotates schemas that hit TypeScript's `.d.ts` serialization limit (TS7056) so `tsc --declaration` stops trying to write the inferred shape. The previous bare `z.ZodType` annotation makes `z.input` resolve to `unknown` — breaking `AdcpToolMap[K]['params']` narrowing for any annotated request schema. Surfaced during the 8.0-beta cut (#1902) when 3.1.0-beta.2's compound schemas pushed four more entries past the TS7056 limit.
Changes
Why land on `main` instead of stacking on the 8.0-beta foundation
Verification on `main` (3.0.12 pin)
Verification on `bokelley/cut-8-0-beta` (3.1.0-beta.2 pin)
Same change applied (verified on stacked PR #1912) — closes the final compile gap on the 8.0-beta foundation. #1912 will be closed in favor of this PR.
Closes #1912 (superseded — same change, broader landing target).
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]