Skip to content

Commit faf33a2

Browse files
MahinAnowarcolinhacksclaude
authored
fix: surface @deprecated on re-exported compat aliases (#6072)
* fix: surface @deprecated on re-exported compat aliases 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. * fix(v4): keep the deprecated ZodType aliases generic `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> --------- Co-authored-by: Colin McDonnell <3084745+colinhacks@users.noreply.github.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
1 parent 3956224 commit faf33a2

2 files changed

Lines changed: 30 additions & 24 deletions

File tree

packages/zod/src/v4/classic/compat.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
import * as core from "../core/index.js";
44
import type { ZodType } from "./schemas.js";
55

6-
export type {
7-
/** @deprecated Use `z.output<T>` instead. */
8-
output as TypeOf,
9-
/** @deprecated Use `z.output<T>` instead. */
10-
output as Infer,
11-
/** @deprecated Use `z.core.$$ZodFirstPartyTypes` instead */
12-
$ZodTypes as ZodFirstPartySchemaTypes,
13-
} from "../core/index.js";
6+
/** @deprecated Use `z.output<T>` instead. */
7+
export type TypeOf<T> = core.output<T>;
8+
/** @deprecated Use `z.output<T>` instead. */
9+
export type Infer<T> = core.output<T>;
10+
/** @deprecated Use `z.core.$$ZodFirstPartyTypes` instead */
11+
export type ZodFirstPartySchemaTypes = core.$ZodTypes;
1412

1513
/** @deprecated Use the raw string literal codes instead, e.g. "invalid_type". */
1614
export const ZodIssueCode = {
@@ -54,14 +52,24 @@ export function getErrorMap(): core.$ZodErrorMap<core.$ZodIssue> | undefined {
5452
return core.config().customError;
5553
}
5654

57-
export type {
58-
/** @deprecated Use z.ZodType (without generics) instead. */
59-
ZodType as ZodTypeAny,
60-
/** @deprecated Use `z.ZodType` */
61-
ZodType as ZodSchema,
62-
/** @deprecated Use `z.ZodType` */
63-
ZodType as Schema,
64-
};
55+
/** @deprecated Use z.ZodType (without generics) instead. */
56+
export type ZodTypeAny<
57+
Output = unknown,
58+
Input = unknown,
59+
Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>,
60+
> = ZodType<Output, Input, Internals>;
61+
/** @deprecated Use `z.ZodType` */
62+
export type ZodSchema<
63+
Output = unknown,
64+
Input = unknown,
65+
Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>,
66+
> = ZodType<Output, Input, Internals>;
67+
/** @deprecated Use `z.ZodType` */
68+
export type Schema<
69+
Output = unknown,
70+
Input = unknown,
71+
Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>,
72+
> = ZodType<Output, Input, Internals>;
6573

6674
/** Included for Zod 3 compatibility */
6775
export type ZodRawShape = core.$ZodShape;

packages/zod/src/v4/classic/errors.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,12 @@ export const ZodRealError: core.$constructor<ZodError> = /*@__PURE__*/ core.$con
7878
Parent: Error,
7979
});
8080

81-
export type {
82-
/** @deprecated Use `z.core.$ZodFlattenedError` instead. */
83-
$ZodFlattenedError as ZodFlattenedError,
84-
/** @deprecated Use `z.core.$ZodFormattedError` instead. */
85-
$ZodFormattedError as ZodFormattedError,
86-
/** @deprecated Use `z.core.$ZodErrorMap` instead. */
87-
$ZodErrorMap as ZodErrorMap,
88-
} from "../core/index.js";
81+
/** @deprecated Use `z.core.$ZodFlattenedError` instead. */
82+
export type ZodFlattenedError<T, U = string> = core.$ZodFlattenedError<T, U>;
83+
/** @deprecated Use `z.core.$ZodFormattedError` instead. */
84+
export type ZodFormattedError<T, U = string> = core.$ZodFormattedError<T, U>;
85+
/** @deprecated Use `z.core.$ZodErrorMap` instead. */
86+
export type ZodErrorMap<T extends core.$ZodIssueBase = core.$ZodIssue> = core.$ZodErrorMap<T>;
8987

9088
/** @deprecated Use `z.core.$ZodRawIssue` instead. */
9189
export type IssueData = core.$ZodRawIssue;

0 commit comments

Comments
 (0)