We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
pipe()
Let's say I want something always to be an array.
const forcedToBeArray = <T>(zodType: ZodType<T>) => { const originalType = z.union([zodType, z.array(zodType)]); const processedType = z.array(zodType); return ( originalType .transform((v) => (!Array.isArray(v) ? [v] : v)) .pipe(processedType) ); }; const expectedTypeScheme = forcedToBeArray( z.object({ t: z.string(), }) ); type ExpectedType = z.infer<typeof expectedTypeScheme>; // { t: string }[]
So far, so good. But nested pipe() will be inferred as an originalType instead of processedType
originalType
processedType
const unexpectedTypeScheme = forcedToBeArray( z.object({ t: forcedToBeArray(z.string()), }) ); type UnExpectedType = z.infer<typeof unexpectedTypeScheme>; // { t: string | string[] }[]
I would expect UnExpectedType to be { t: string[] }[]
UnExpectedType
{ t: string[] }[]
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Let's say I want something always to be an array.
So far, so good. But nested pipe() will be inferred as an
originalType
instead ofprocessedType
I would expect
UnExpectedType
to be{ t: string[] }[]
The text was updated successfully, but these errors were encountered: