From eaf4f75095e0198d747d5c1000ec41ae97a15325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20=C5=9Eafak?= Date: Mon, 18 Sep 2023 20:01:28 -0700 Subject: [PATCH] Make validators accept ZodEffects to handle refined schemas Fixes #45 --- .changeset/support-refined-schema.md | 4 ++++ src/lib/internal/super-form-patch.ts | 5 ++++- src/routes/examples/schemas.ts | 2 -- 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 .changeset/support-refined-schema.md diff --git a/.changeset/support-refined-schema.md b/.changeset/support-refined-schema.md new file mode 100644 index 0000000..37dbafd --- /dev/null +++ b/.changeset/support-refined-schema.md @@ -0,0 +1,4 @@ +--- +"formsnap": patch +--- +Fix handling of refined zod schemas so as not to throw false type errors. \ No newline at end of file diff --git a/src/lib/internal/super-form-patch.ts b/src/lib/internal/super-form-patch.ts index c476648..355950c 100644 --- a/src/lib/internal/super-form-patch.ts +++ b/src/lib/internal/super-form-patch.ts @@ -261,7 +261,10 @@ export type SuperFormOptions, M> = Partial }) => MaybePromise); dataType: "form" | "json"; jsonChunkSize: number; - validators: SuperValidators; + validators: + | false + | SuperValidators> + | ZodValidation>; validationMethod: "auto" | "oninput" | "onblur" | "submit-only"; defaultValidator: "keep" | "clear"; customValidity: boolean; diff --git a/src/routes/examples/schemas.ts b/src/routes/examples/schemas.ts index 9a4868b..e33eb42 100644 --- a/src/routes/examples/schemas.ts +++ b/src/routes/examples/schemas.ts @@ -40,5 +40,3 @@ export const simpleFormSchema = z.object({ message: "You need to accept the terms and conditions" }) }); - -export type SomeFormSchema = typeof someFormSchema;