From d79fbcd421357cd2c291eba76a43255aa2e0b71b Mon Sep 17 00:00:00 2001 From: Saiichi Hashimoto Date: Wed, 8 Jun 2022 10:59:14 -0500 Subject: [PATCH] fix(types): fixing zod type inference --- src/array/index.ts | 14 +++++++------- src/types.ts | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/array/index.ts b/src/array/index.ts index 4807bb3..17165ee 100644 --- a/src/array/index.ts +++ b/src/array/index.ts @@ -91,7 +91,7 @@ const itemsInternal = < zod, parse: zod.parse.bind(zod), // FIXME Mock the array element types. Not sure how to allow an override, since the function has to be defined before we know the element types. - mock: () => [] as unknown as z.infer>, + mock: () => [] as unknown as z.input>, schema: () => items.map(({ schema }) => schema()), item: < Zod extends z.ZodType, @@ -124,8 +124,8 @@ interface ArrayType< > extends SanityType< Omit< TypeValidation< - Schema.ArrayDefinition>>, - z.infer> + Schema.ArrayDefinition>>, + z.input> >, FieldOptionKeys >, @@ -141,15 +141,15 @@ export const array = < >( def: Omit< TypeValidation< - Schema.ArrayDefinition>>, - z.infer> + Schema.ArrayDefinition>>, + z.input> >, FieldOptionKeys | "of" | "type" > & { length?: number; max?: number; min?: number; - mock?: (faker: Faker) => z.infer>; + mock?: (faker: Faker) => z.input>; nonempty?: NonEmpty; of: ItemsType; } @@ -162,7 +162,7 @@ export const array = < of: { schema: itemsSchema, mock: itemsMock, zod: itemsZod }, mock = itemsMock as unknown as ( faker: Faker - ) => z.infer>, + ) => z.input>, validation, } = def; diff --git a/src/types.ts b/src/types.ts index e969843..36bf4b9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -9,7 +9,7 @@ import type { z } from "zod"; export interface SanityType> { mock: () => z.input; - parse: (data: unknown) => z.infer; + parse: (data: unknown) => z.output; schema: () => Definition; zod: Zod; }