core.d.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import type * as errors from "./errors.js";
  2. import type * as schemas from "./schemas.js";
  3. import type { Class } from "./util.js";
  4. type ZodTrait = {
  5. _zod: {
  6. def: any;
  7. [k: string]: any;
  8. };
  9. };
  10. export interface $constructor<T extends ZodTrait, D = T["_zod"]["def"]> {
  11. new (def: D): T;
  12. init(inst: T, def: D): asserts inst is T;
  13. }
  14. /** A special constant with type `never` */
  15. export declare const NEVER: never;
  16. export declare function $constructor<T extends ZodTrait, D = T["_zod"]["def"]>(name: string, initializer: (inst: T, def: D) => void, params?: {
  17. Parent?: typeof Class;
  18. }): $constructor<T, D>;
  19. export declare const $brand: unique symbol;
  20. export type $brand<T extends string | number | symbol = string | number | symbol> = {
  21. [$brand]: {
  22. [k in T]: true;
  23. };
  24. };
  25. export type $ZodBranded<T extends schemas.SomeType, Brand extends string | number | symbol, Dir extends "in" | "out" | "inout" = "out"> = T & (Dir extends "inout" ? {
  26. _zod: {
  27. input: input<T> & $brand<Brand>;
  28. output: output<T> & $brand<Brand>;
  29. };
  30. } : Dir extends "in" ? {
  31. _zod: {
  32. input: input<T> & $brand<Brand>;
  33. };
  34. } : {
  35. _zod: {
  36. output: output<T> & $brand<Brand>;
  37. };
  38. });
  39. export type $ZodNarrow<T extends schemas.SomeType, Out> = T & {
  40. _zod: {
  41. output: Out;
  42. };
  43. };
  44. export declare class $ZodAsyncError extends Error {
  45. constructor();
  46. }
  47. export declare class $ZodEncodeError extends Error {
  48. constructor(name: string);
  49. }
  50. export type input<T> = T extends {
  51. _zod: {
  52. input: any;
  53. };
  54. } ? T["_zod"]["input"] : unknown;
  55. export type output<T> = T extends {
  56. _zod: {
  57. output: any;
  58. };
  59. } ? T["_zod"]["output"] : unknown;
  60. export type { output as infer };
  61. export interface $ZodConfig {
  62. /** Custom error map. Overrides `config().localeError`. */
  63. customError?: errors.$ZodErrorMap | undefined;
  64. /** Localized error map. Lowest priority. */
  65. localeError?: errors.$ZodErrorMap | undefined;
  66. /** Disable JIT schema compilation. Useful in environments that disallow `eval`. */
  67. jitless?: boolean | undefined;
  68. }
  69. export declare const globalConfig: $ZodConfig;
  70. export declare function config(newConfig?: Partial<$ZodConfig>): $ZodConfig;