#Preserve zod schema type in generic function

5 messages · Page 1 of 1 (latest)

sharp ember
#

Basically I'm trying to preserve the type of the zod schema passed into a function that operates on that schema and returns a modified version of it. Playground example below:

grand garnetBOT
#
littlelily#0

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
...```

opal mist
#

this seems to work:

grand garnetBOT
#
mkantor#0

Preview:ts ... const partialSchemaShape = <T extends ZodRawShape>( schema: ZodObject<T> ) => schema.partial().shape ...

sharp ember
#

thanks! dont know why i didnt think of that