diff --git a/src/__tests__/createSchemaForm.test.tsx b/src/__tests__/createSchemaForm.test.tsx index 3b87638..4ba342c 100644 --- a/src/__tests__/createSchemaForm.test.tsx +++ b/src/__tests__/createSchemaForm.test.tsx @@ -22,6 +22,7 @@ import { useReqDescription, useTsController, } from "../FieldContext"; +import { expectTypeOf } from "expect-type"; import { createUniqueFieldSchema } from "../createFieldSchema"; const testIds = { @@ -767,7 +768,8 @@ describe("createSchemaForm", () => { render(
{}} />); }).toThrow(); }); - it("should correctly type the form with multiple unique field schemas.", () => { + + it("should have correct typings with multiple unique field schemas when transform and refine are used.", () => { const A = createUniqueFieldSchema(z.string(), "one"); const B = createUniqueFieldSchema(z.string(), "two"); function In1(_: { req: string }) { @@ -784,11 +786,16 @@ describe("createSchemaForm", () => { const Form = createTsForm(mapping); {}} + schema={z + .object({ + a: A, + b: B, + }) + .refine((_) => true) + .transform((a) => a.a)} + onSubmit={(data) => { + expectTypeOf(data).toBeString(); + }} props={{ a: { req: "One", diff --git a/src/createSchemaForm.tsx b/src/createSchemaForm.tsx index 333b624..23d31b1 100644 --- a/src/createSchemaForm.tsx +++ b/src/createSchemaForm.tsx @@ -90,8 +90,10 @@ export type ExtraProps = { type UnwrapEffects> = T extends AnyZodObject ? T - : T extends ZodEffects - ? T["_def"]["schema"] + : T extends ZodEffects + ? EffectsSchema extends ZodEffects + ? EffectsSchemaInner + : EffectsSchema : never; function checkForDuplicateTypes(array: RTFSupportedZodTypes[]) { @@ -237,7 +239,7 @@ export function createTsForm< /** * A callback function that will be called with the data once the form has been submitted and validated successfully. */ - onSubmit: (values: z.infer>) => void; + onSubmit: (values: z.infer) => void; /** * Initializes your form with default values. Is a deep partial, so all properties and nested properties are optional. */ @@ -296,7 +298,7 @@ export function createTsForm< */ props?: RequireKeysWithRequiredChildren< Partial<{ - [key in keyof z.infer]: Mapping[IndexOf< + [key in keyof z.infer>]: Mapping[IndexOf< UnwrapMapping, readonly [ IndexOfUnwrapZodType<