0.1.3 #4
@@ -11,15 +11,32 @@ export function stripZodObjectDefaults<
|
|||||||
>(
|
>(
|
||||||
schema: z.ZodObject<T, UnknownKeys, Catchall, Output, Input>
|
schema: z.ZodObject<T, UnknownKeys, Catchall, Output, Input>
|
||||||
) {
|
) {
|
||||||
return schema.extend(
|
const s = schema.extend(
|
||||||
mapValues(schema.shape, v =>
|
mapValues(schema.shape, v =>
|
||||||
v instanceof z.ZodDefault
|
v instanceof z.ZodDefault
|
||||||
? v.removeDefault()
|
? v.removeDefault()
|
||||||
: v
|
: v
|
||||||
) as {
|
) as {
|
||||||
[K in keyof T]: T[K] extends z.ZodDefault<infer NestedDef>
|
[K in keyof T]: T[K] extends z.ZodDefault<infer Def>
|
||||||
? NestedDef
|
? Def
|
||||||
: T[K]
|
: T[K]
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type test = z.input<typeof s>
|
||||||
|
return s as unknown as z.ZodObject<
|
||||||
|
{
|
||||||
|
[K in keyof T]: T[K] extends z.ZodDefault<infer Def>
|
||||||
|
? Def
|
||||||
|
: T[K]
|
||||||
|
},
|
||||||
|
UnknownKeys,
|
||||||
|
Catchall,
|
||||||
|
{
|
||||||
|
[K in keyof z.output<typeof s>]: T[K] extends z.ZodDefault<infer Def>
|
||||||
|
? Def
|
||||||
|
: T[K]
|
||||||
|
},
|
||||||
|
Input
|
||||||
|
>
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user