Open shunjilin opened 3 weeks ago
You raise a very good issue here. The problem I think was that we supported Yup
by default, which caused the typed schema type inference to short circuit most of the time or resolve to incorrect types all together. So I handicapped the resolution.
if you want to try to give it another go by limiting the types go a head, But it would be a matter of seeing if this qualifies as a breaking change or not. If it is then maybe we should consider this for v5 with more aggressive changes like dropping yup
built-in support.
Thank you for the explanation! Understand the concern about this being a breaking change, will take a quick look to see if this can be mitigated, e.g. with an explicit typed flag
Description:
I’m not sure if this issue has already been addressed or if it’s a limitation, so I apologize if this is redundant.
Currently, the validationSchema accepts any as its type, which allows any value to be assigned. In the example below:
Solution
Would it be possible to narrow down the type of validationSchema to at least one of the following:
For reference, see docs.
Context:
I’m raising this because we had a case where we changed the Form type, but forgot to update the validationSchema. This led to an invalid property being set as required, causing the form to fail submission. Having stronger type safety for validationSchema would help prevent such issues.
Alternatives
A straightforward solution to this would be to use the
typedSchema
fromyup
orzod
, but since we are already using another validation libraryeffect-ts
, we would like to avoid introducing an additional dependency.I’d be happy to contribute if this approach seems suitable. Thanks!