MCPcopy
hub / github.com/colinhacks/zod / stripOuter

Function stripOuter

packages/zod/src/v3/tests/generics.test.ts:8–17  ·  view source on GitHub ↗
(schema: TData, data: unknown)

Source from the content-addressed store, hash-verified

6
7test("generics", () => {
8 async function stripOuter<TData extends z.ZodTypeAny>(schema: TData, data: unknown) {
9 return z
10 .object({
11 nested: schema, // as z.ZodTypeAny,
12 })
13 .transform((data) => {
14 return data.nested!;
15 })
16 .parse({ nested: data });
17 }
18
19 const result = stripOuter(z.object({ a: z.string() }), { a: "asdf" });
20 util.assertEqual<typeof result, Promise<{ a: string }>>(true);

Callers 1

generics.test.tsFile · 0.70

Calls 2

transformMethod · 0.80
parseMethod · 0.65

Tested by

no test coverage detected