TanStackT
TanStack10mo ago
13 replies
radical-lime

Re-using a generic sub-form agnostic of it's parent form gives TS errors

Hi!

First off: thanks for creating an amazing form library. I'm super happy with it so far! Really good stuff.

What I've stumbled across may just be a typescript bug. I'm not sure if it's me using the library wrong, if it's a bug or if it's simply not supported. But what I'm trying to do is to have two separate forms (with different schemas) re-use the same sub-form by leveraging the withForm-HoC.

When I try to do that I get a type error when passing the form to the child component. It seems it's not able to realize that the child form implements a sub-set of the parent's schema. Attaching a minimal example in the post below.

The forms both work just fine, it's just typescript yelling at me. Not sure if what I'm trying to do here is completely antipattern, but to my understanding this is how the composition library is meant to be used. I.e. the withForm should be able to delivery generic sub-forms that can be plugged in anywhere. Or am I mistaken?
Was this page helpful?