Skip to content

fix: surface @deprecated on re-exported compat aliases - #6072

Merged
colinhacks merged 2 commits into
colinhacks:mainfrom
MahinAnowar:fix/propagate-deprecated-jsdoc
Aug 13, 2026
Merged

fix: surface @deprecated on re-exported compat aliases#6072
colinhacks merged 2 commits into
colinhacks:mainfrom
MahinAnowar:fix/propagate-deprecated-jsdoc

Conversation

@MahinAnowar

Copy link
Copy Markdown
Contributor

Closes #6038.

@deprecated written on an export { 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, and BRAND already use in compat.ts — so the tag survives re-export.

Verified against the built .d.ts via 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 emitted const declarations as well).

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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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)

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@wahajahmed010 wahajahmed010 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@MahinAnowar

Copy link
Copy Markdown
Contributor Author

Thanks for taking a look!

On _max/_min: agreed it's a non-issue — export const _max = _lte just aliases an @__NO_SIDE_EFFECTS__-annotated function, so bundlers tree-shake it the same as the previous export { _lte as _max }; the circular-deps check and both TS test jobs stay green.

On tests: a @deprecated symbol doesn't produce a compile error, so there's no clean runtime/type-assertion hook. I verified it at the declaration level via the language service instead — a fixture importing these through the package entry reports 0 deprecation diagnostics (6385) on main and 9 after this change. Happy to add a committed .d.ts/language-service check if the maintainers want one, though it'd need a build step the current suite doesn't do.

`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>
@colinhacks

Copy link
Copy Markdown
Owner

Pushed two changes on top of this.

ZodTypeAny, ZodSchema and Schema were re-exports of ZodType, so they inherited its three defaulted type parameters. Redeclaring them as bare aliases surfaces the tag but collapses them to zero arity, which breaks z.ZodSchema<string> with TS2315 — the Zod 3 idiom this compat layer exists to serve. I restated the parameters and forwarded them.

I also reverted 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, so that change fixed nothing and traded a hoisted function re-export for a TDZ-bound const.

Verified against the built .d.ts with the language service: all nine type aliases now report deprecated where none did before, and _max/_min still do. Merging once CI is green. Also closed #6265, which covered three of the same aliases.

@colinhacks
colinhacks merged commit faf33a2 into colinhacks:main Aug 13, 2026
7 checks passed
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.

@deprecated JSDocs not propagated

3 participants