fix: restore zod 4 schema output type inference (CI auto-fix for #1405) - #1406
Closed
github-actions[bot] wants to merge 1 commit into
Closed
fix: restore zod 4 schema output type inference (CI auto-fix for #1405)#1406github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
zod 4 marks the schema output type parameter as `out` (covariant), so the compiler can no longer infer it from a value parameter. The JsonBodySchema<T> constraint in request-body.ts tried to infer T that way, which regressed to `unknown` for every parsed body and produced 39 typecheck errors across all v1 resource handlers. Switch parseJsonBody/parseHonoJsonBody to be generic over the schema type S and derive its output via a SchemaOutput<S> conditional on the `_output` phantom property (which zod still resolves correctly). Also annotate four zod .transform()/.refine() callbacks whose input type stopped being inferred. Type-only changes; no runtime behavior modified. CI Run: https://github.com/ding113/claude-code-hub/actions/runs/31245429109 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
CI Auto-Fix
Original PR: #1405
Failed CI Run: PR Build Check
Failed Job: Code Quality Check (
tsgotypecheck)Root Cause
The repo ships no lockfile (
bun.lockis gitignored since 58f6657), so CI resolveszod@^4.4.3to the latest 4.x on every run. A recent zod 4 release marks the schema output type parameter asout(covariant). TheJsonBodySchema<T>constraint inrequest-body.tsinferredTfrom a value (parameter) position, which TypeScript cannot do for a covariant type parameter — so every parsed body regressed tounknown, producing 39 typecheck errors across all v1 resource handlers.This is pre-existing on
dev(PR #1405 does not touch any of these files) and surfaces on this PR because the merge commit inherits dev's typecheck.Fixes Applied
src/lib/api/v1/_shared/request-body.tsparseJsonBody/parseHonoJsonBodyfrom generic<T>(inferred from variance-blocked param) to generic<S extends JsonBodySchema>+SchemaOutput<S>conditional on zod's_outputphantom propertysrc/app/api/v1/resources/providers/handlers.tsSchemaOutput<S>pattern to the localparseJsonwrappersrc/lib/api/v1/schemas/audit-logs.ts.transform()callback param ("true" | "false" | undefined)src/lib/api/v1/schemas/me.ts.transform()callback param (boolean | "true" | "false")src/lib/api/v1/schemas/system-config.ts.refine()callback param (string)src/lib/api/v1/schemas/usage-logs.ts.transform()callback param (boolean | "true" | "false")All changes are type-only — no runtime behavior is modified. The
parsed.data as SchemaOutput<S>cast is correct becausesafeParsehas already validated the data against schemaS, soSchemaOutput<S>is by definition the validated output type.Verification
bun run typecheck(tsgo) passes — all 39 errors resolvedbun run lintpassestests/unit/api/v1/— 156 tests pass (34 files)Auto-generated by Claude AI
Greptile Summary
This PR restores Zod 4 output-type inference for management API JSON body parsing without changing runtime validation behavior.
_outputphantom type in shared and provider-specific body parsers.Confidence Score: 5/5
The PR appears safe to merge, with no concrete changed-code defect identified.
The schema output extraction preserves types for the Zod schemas used by current callers, and each callback annotation matches the input type of its immediately preceding schema without altering runtime behavior.
Important Files Changed
Reviews (1): Last reviewed commit: "fix(api): restore zod 4 schema output ty..." | Re-trigger Greptile
Context used: