Skip to content
Discussion options

You must be logged in to vote

Great question! In TypeScript, typeof LexiconsSchema gives you the type of the schema object itself (i.e., the Zod schema instance), not the type of the data it validates.

z.infer<typeof LexiconsSchema> is a Zod utility that extracts the TypeScript type of the data that would successfully pass validation by your schema. So in your example, Lexicons will be the type of the validated data (like Map<string, LexiconDetail>), not the schema object.

You need both: typeof to reference the schema, and z.infer to get the validated data type. This pattern is standard in Zod and lets you keep your runtime validation and static typing in sync. More details and examples are in the Zod docs.

To reply,…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by otakutyrant
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant