Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type definition ZodFirstPartySchemaTypes is missing some first party schema types #3246

Closed
MatthijsMud opened this issue Feb 16, 2024 · 0 comments · Fixed by #3247
Closed

Comments

@MatthijsMud
Copy link
Contributor

While trying to create an object which maps from ZodFirstPartyTypeKind to a function that takes the associated schema as argument, I found that ZodReadonly and ZodSymbol are missing from ZodFirstPartySchemaTypes union. The basic premise of the mapping is as follows.

type ZodFirstPartySchemaForType<T extends ZodFirstPartyTypeKind> = ZodFirstPartySchemaTypes extends infer Schema 
  ? Schema extends { _def: { typeName: T} } 
    ? Schema 
    : never
  : never;
type ZodSchemaMap = { [key in ZodFirstPartyTypeKind]: ZodFirstPartySchemaForType<key> };

Based on this mapping we could then infer which types are missing:

type MissingSchemaTypes = { [key in keyof ZodSchemaMap as ZodSchemaMap[key] extends { _def: never } ? key : never ]: true }

image

zod/src/types.ts

Lines 4941 to 4976 in 76c8ace

export type ZodFirstPartySchemaTypes =
| ZodString
| ZodNumber
| ZodNaN
| ZodBigInt
| ZodBoolean
| ZodDate
| ZodUndefined
| ZodNull
| ZodAny
| ZodUnknown
| ZodNever
| ZodVoid
| ZodArray<any, any>
| ZodObject<any, any, any>
| ZodUnion<any>
| ZodDiscriminatedUnion<any, any>
| ZodIntersection<any, any>
| ZodTuple<any, any>
| ZodRecord<any, any>
| ZodMap<any>
| ZodSet<any>
| ZodFunction<any, any>
| ZodLazy<any>
| ZodLiteral<any>
| ZodEnum<any>
| ZodEffects<any, any, any>
| ZodNativeEnum<any>
| ZodOptional<any>
| ZodNullable<any>
| ZodDefault<any>
| ZodCatch<any>
| ZodPromise<any>
| ZodBranded<any, any>
| ZodPipeline<any, any>;

Could be related to #2663

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 a pull request may close this issue.

1 participant