Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using forward and partialCheck like the password compare example results in multiple type errors #987

Open
matthew-dean opened this issue Dec 18, 2024 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@matthew-dean
Copy link

Reproduction example here

const FormSchema = pipe(
  object({
    password: pipe(string(), minLength(6), maxLength(18)),
    confirmPassword: string(),
  }),
  forward(
    partialCheck(
      [['password'], ['confirmPassword']],
      (input) => input.password === input.confirmPassword,
      'The two passwords do not match.'
    ),
    ['confirmPassword']
  )
);

I don't get errors in TypeScript language services, but the reproduction example fails to compile in tsc / vue-tsc.

The two errors are:

  • error TS2589: Type instantiation is excessively deep and possibly infinite.
  • error TS2339: Property 'confirmPassword' does not exist on type '{ password: string; }'
@matthew-dean
Copy link
Author

Workaround:

I got this working with this workaround (which also compiled much, much faster):

const FormSchema = pipe(
  object({
    password: pipe(string(), minLength(6), maxLength(18)),
    confirmPassword: string()
  }),
  forward<{
    password: string
    confirmPassword: string
  }, PartialCheckIssue<{
    password: string
    confirmPassword: string
  }>>(
    partialCheck(
      [['password'], ['confirmPassword']],
      input => input.password === input.confirmPassword,
      'The two passwords do not match.'
    ),
    ['confirmPassword']
  )
)

So it seems like type-inference from partialCheck + type inference into forward is just too complex with this simple example.

@fabian-hiller
Copy link
Owner

Not sure there is anything we can do about this. Having the path argument of partialCheck and forward typesafe is a great DX, but also results in a complex TS type that can cause such problems.

@fabian-hiller fabian-hiller self-assigned this Dec 19, 2024
@fabian-hiller fabian-hiller added the question Further information is requested label Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants