typescript - Infer zod schema shape from sibling property? - Stack Overflow

admin2025-04-16  6

Given the following Typescript blurb:

import { z, ZodType, infer as ZodInfer } from "zod";

type TransformEntry<T extends ZodType = ZodType> = {
    schema: T;
    transform: (value: ZodInfer<T>) => void;
};

const myEntry:TransformEntry = {
    schema: z.object({
        firstName: z.string()
    }),
    transform: (value) => {
        // value resolves as any
    }
}

I would like the value property in the transform function to resolve as an object that matches the zod schema, like {firstName:string}, but for some reason it resolves as any. What am I doing wrong here?

转载请注明原文地址:http://www.anycun.com/QandA/1744746489a87027.html