Skip to content
Discussion options

You must be logged in to vote

Your type error occurs because conditional types like z.$output extends string ? string[] : never do not work as you expect in this context. z.$output is not a type alias for the output of a specific schema, but rather a generic utility type that requires a type parameter(1)(2). It is meant to be used as z.$output<typeof schema>, not as a bare type.

So, when you write:

type MyMeta = { examples: z.$output extends string ? string[] : never };

You are not passing a schema type to z.$output, so TypeScript cannot resolve what z.$output is, and the conditional type collapses to never(1)(2). That's why assigning a string[] produces the error.

To get the output type of a specific schema (e.g., z.…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@baptisteArno
Comment options

Answer selected by baptisteArno
Comment options

You must be logged in to vote
0 replies
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