pablo-abc / felte

An extensible form library for Svelte, Solid and React
https://felte.dev
MIT License
1.02k stars 44 forks source link

"Type instantiation is excessively deep and possibly infinite" with Zod validator #166

Open pzuraq opened 2 years ago

pzuraq commented 2 years ago

Describe the bug

With a new empty project when creating a form with the Zod validator, TypeScript will throw "Type instantiation is excessively deep and possibly infinite". This is without any extra type information being extracted to feed into the form, so it could be due to type inference.

import { createForm } from 'felte';
import { validator } from '@felte/validator-zod';
import * as z from 'zod';

const schema = z.object({
  email: z.string().email().nonempty(),
  password: z.string().nonempty(),
});

const { form } = createForm({
  validate: validator({ schema }),
});

Which package/s are you using?

felte (Svelte), @felte/validator-zod

Environment

{
  "devDependencies": {
    "@felte/validator-zod": "^1.0.10",
    "felte": "^1.2.2",
    "typescript": "^4.7.4",
    "zod": "^3.17.10"
  }
}

To reproduce

Install the dependencies, copy the code snippet into a fresh TS project, and run TS typechecking.

Small reproduction example

No response

Screenshots

No response

Additional context

No response

Frantss commented 1 year ago

Running into the same issue with Solid. Tried to fix but with no luck, from my investigation the actual error was caused by the Extender type, which is weird since it is also used in other validators, like yup