zod
zod copied to clipboard
How would I extract first property type from zod object?
Here is what I got:
import {
z,
type ZodTypeAny,
} from 'zod';
const foo = z.object({
name: z.string(),
});
const bar = <T extends ZodTypeAny>(shape: T) /* ??? */ => {
return null as any;
};
const baz = bar(foo);
console.log(baz);
I need baz to be first/any property value of foo, i.e. in this case it should be string.
How would I extract first property type from zod object?
I think it should be:
const bar = <T extends ZodTypeAny>(shape: T): z.infer<T>[keyof z.infer<T>] => {
return null as any;
};
although not 100% sure