fix: surface @deprecated on re-exported compat aliases - #6072
Conversation
JSDoc `@deprecated` placed on `export { X as Y }` / `export type { X as Y }`
specifiers is dropped when the alias is re-exported again, so IDEs never
flagged `ZodTypeAny`, `ZodSchema`, `Schema`, `TypeOf`, `Infer`,
`ZodFirstPartySchemaTypes`, `ZodFlattenedError`, `ZodFormattedError`,
`ZodErrorMap`, `_max` or `_min` as deprecated. Declare each as a standalone
aliased declaration (matching inferFlattenedErrors/BRAND) so the tag
propagates to the emitted types.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — converts export type { X as Y } re-exports to standalone export type Y = X declarations so that @deprecated JSDoc survives the re-export chain through the package entry.
compat.ts— 6 type aliases (TypeOf,Infer,ZodFirstPartySchemaTypes,ZodTypeAny,ZodSchema,Schema)errors.ts— 3 type aliases (ZodFlattenedError,ZodFormattedError,ZodErrorMap)api.ts— 2 value aliases (_max,_min)
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
wahajahmed010
left a comment
There was a problem hiding this comment.
This is a well-scoped fix for a real DX issue. Verified the problem — JSDoc @deprecated tags on export type { X as Y } re-exports don\u2019t survive the TypeScript declaration emitter in many cases. The approach (redeclare aliases as standalone type aliases with the JSDoc attached directly) is the standard workaround.
Logic: Correct. The change from export type { X as Y } to export type Y = X preserves semantic equivalence for consumers while letting the JSDoc tag survive.
One thing to double-check: _max and _min changed from export { ... as ... } (re-exports of existing function declarations) to export const _max = _lte. This changes the runtime semantics slightly — they are now new const bindings rather than alias re-exports. In practice this is fine (same reference for const), but verify that tools/transformers that tree-shake based on export origin don\u2019t misbehave. Not a blocker, just worth noting.
Tests: No tests added. For a pure type-declaration change this makes sense, but adding a quick .d.ts snapshot or a language-service check would prevent regressions.
Verified count: 8 aliases fixed (TypeOf, Infer, ZodFirstPartySchemaTypes, ZodTypeAny, ZodSchema, Schema, ZodFlattenedError, ZodFormattedError, ZodErrorMap) + 2 _max/_min value aliases. That matches the \u201c9 after\u201d claim in the description.
Clean fix, good documentation.
|
Thanks for taking a look! On On tests: a |
`ZodTypeAny`, `ZodSchema` and `Schema` were re-exports of `ZodType`, so they inherited its three defaulted type parameters. Redeclaring them as `export type ZodSchema = ZodType` surfaces the `@deprecated` tag but collapses them to zero arity, so `z.ZodSchema<string>` — the Zod 3 idiom this compat layer exists to serve — stops compiling with TS2315. Restate the parameters and forward them. Also revert the `core/api.ts` hunk. `_max` and `_min` are value re-exports, and TypeScript already reports their deprecation through the alias; only type-only export specifiers drop the tag. The change traded a hoisted function re-export for a TDZ-bound const and fixed nothing. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Pushed two changes on top of this.
I also reverted the Verified against the built |

Closes #6038.
@deprecatedwritten on anexport { X as Y }/export type { X as Y }specifier is dropped once the alias is re-exported again through the package entry, so none of the Zod 3 compat aliases actually rendered as deprecated in editors —ZodTypeAny,ZodSchema,Schema,TypeOf,Infer,ZodFirstPartySchemaTypes(compat.ts),ZodFlattenedError,ZodFormattedError,ZodErrorMap(errors.ts), and_max/_min(core/api.ts).This redeclares each as a standalone aliased declaration with the JSDoc attached directly — the same form
inferFlattenedErrors,inferFormattedError, andBRANDalready use in compat.ts — so the tag survives re-export.Verified against the built
.d.tsvia the language service: a fixture importing these through the package entry reports 0 deprecation diagnostics (6385) before the change and 9 after (the two_value aliases carry the tag on their emittedconstdeclarations as well).