#Preserve zod schema type in generic function
5 messages · Page 1 of 1 (latest)
Preview:```ts
import {z, ZodObject} from "zod"
const user = z.object({
id: z.number(),
name: z.string(),
})
// how to type this to not introduce any into return type
const partialSchemaShape = <
TSchema extends ZodObject<any>
(
schema: TSchema
) => schema.partial().shape
...```
You can choose specific lines to embed by selecting them before copying the link.
this seems to work:
Preview:ts ... const partialSchemaShape = <T extends ZodRawShape>( schema: ZodObject<T> ) => schema.partial().shape ...
thanks! dont know why i didnt think of that