0.1.3 #4

Merged
Thilawyn merged 74 commits from next into master 2024-03-24 22:24:25 +01:00
2 changed files with 26 additions and 0 deletions
Showing only changes of commit d7c8fd1a2d - Show all commits

View File

@@ -2,3 +2,4 @@ export * from "./class"
export * from "./effect"
export * from "./extend"
export * from "./misc"
export * from "./zod"

25
src/util/zod.ts Normal file
View File

@@ -0,0 +1,25 @@
import { mapValues } from "lodash-es"
import { z } from "zod"
export function stripZodObjectDefaults<
T extends z.ZodRawShape,
UnknownKeys extends z.UnknownKeysParam,
Catchall extends z.ZodTypeAny,
Output,
Input,
>(
schema: z.ZodObject<T, UnknownKeys, Catchall, Output, Input>
) {
return schema.extend(
mapValues(schema.shape, v =>
v instanceof z.ZodDefault
? v.removeDefault()
: v
) as {
[K in keyof T]: T[K] extends z.ZodDefault<infer NestedDef>
? NestedDef
: T[K]
}
)
}