Skip to content
This repository has been archived by the owner on May 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #50 from saiichihashimoto/fix-zod-inference
Browse files Browse the repository at this point in the history
fix(types): fixing zod type inference
  • Loading branch information
kodiakhq[bot] authored Jun 8, 2022
2 parents 8d99909 + d79fbcd commit 5ee8a42
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/array/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ZodArray<Positions, Items, NonEmpty>>,
mock: () => [] as unknown as z.input<ZodArray<Positions, Items, NonEmpty>>,
schema: () => items.map(({ schema }) => schema()),
item: <
Zod extends z.ZodType<any, any, any>,
Expand Down Expand Up @@ -124,8 +124,8 @@ interface ArrayType<
> extends SanityType<
Omit<
TypeValidation<
Schema.ArrayDefinition<z.infer<ZodArray<Positions, Items, NonEmpty>>>,
z.infer<ZodArray<Positions, Items, NonEmpty>>
Schema.ArrayDefinition<z.input<ZodArray<Positions, Items, NonEmpty>>>,
z.input<ZodArray<Positions, Items, NonEmpty>>
>,
FieldOptionKeys
>,
Expand All @@ -141,15 +141,15 @@ export const array = <
>(
def: Omit<
TypeValidation<
Schema.ArrayDefinition<z.infer<ZodArray<Positions, Items, NonEmpty>>>,
z.infer<ZodArray<Positions, Items, NonEmpty>>
Schema.ArrayDefinition<z.input<ZodArray<Positions, Items, NonEmpty>>>,
z.input<ZodArray<Positions, Items, NonEmpty>>
>,
FieldOptionKeys | "of" | "type"
> & {
length?: number;
max?: number;
min?: number;
mock?: (faker: Faker) => z.infer<ZodArray<Positions, Items, NonEmpty>>;
mock?: (faker: Faker) => z.input<ZodArray<Positions, Items, NonEmpty>>;
nonempty?: NonEmpty;
of: ItemsType<Positions, Items>;
}
Expand All @@ -162,7 +162,7 @@ export const array = <
of: { schema: itemsSchema, mock: itemsMock, zod: itemsZod },
mock = itemsMock as unknown as (
faker: Faker
) => z.infer<ZodArray<Positions, Items, NonEmpty>>,
) => z.input<ZodArray<Positions, Items, NonEmpty>>,
validation,
} = def;

Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { z } from "zod";

export interface SanityType<Definition, Zod extends z.ZodType<any, any, any>> {
mock: () => z.input<Zod>;
parse: (data: unknown) => z.infer<Zod>;
parse: (data: unknown) => z.output<Zod>;
schema: () => Definition;
zod: Zod;
}
Expand Down

0 comments on commit 5ee8a42

Please sign in to comment.