Skip to content

.pipe seems arbitrarily restricted in V4 #4778

@ConnorSinnott

Description

@ConnorSinnott

Hello! I'm in the process of migrating to v4 and the largest headache so far has been the changes to .pipe. From what I'm gathering from errors, whatever schema is being piped to must have the input match the output of the source schema.

For my specific example, I had a JSON parsing schema which accepts a string and parses the result as JSON returning an object. I'd then pipe that into whatever schema I needed that object to match. This doesn't appear to be supported anymore since the input requirement for pipe can not be determined.

import { z } from 'zod/v4';

export const someStringSchema = z.string();

const someObjectSchema: z.ZodSchema = z.object({ // Arbitrarily erasing the inferred type to be just ZodSchema
  name: z.string(),
})

someStringSchema.pipe(someObjectSchema).parse({}) 
// Types of property _zod are incompatible.
// Type $ZodTypeInternals<unknown, unknown> is not assignable to type $ZodTypeInternals<any, string>
// Type unknown is not assignable to type string

I can apparently calm the linter by defining z.ZodSchema<any, any>

import { z } from 'zod/v4';

export const someStringSchema = z.string();

const someObjectSchema: z.ZodSchema<any, any> = z.object({
  name: z.string(),
})

someStringSchema.pipe(someObjectSchema).parse({}) // No issues

I guess I can see why perhaps a developer would want to be warned that they are piping an incompatible type, but this seems to hinder abstract Zod work.

Any suggestions?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions