7 Replies
deep-jadeOP•3w ago
It feels weird to pass the same defaultValues twice.
On
PersonalInfoSection
I don't have a TS error. On AddressSection
I do.
I understand why, it's just unclear to me if that's the way to do it.
is the purpose of defaultValues in PersonalInfoSection to define the type without having an impact on the actual form values?
should I do {} as MyType
instead then?flat-fuchsia•3w ago
the simplest way would be to create a shared
formOptions()
instead.
withForm does a strict check to ensure only data that matches your form inside can be used. That includes validators, defaultValues and transforms.
It doesn‘t use the defaultValues internally, so if you want to cast the type instead, that‘s fine. Just keep in mind that this is not true for field groupsflat-fuchsia•3w ago
there‘s actually a PR to make formOptions more useable now (because the typing was off before), so if you want to give that a spin to confirm it, you can find the install links here: https://github.com/TanStack/form/pull/1679
GitHub
fix(form-core): improve formOptions type preservation - WIP by a-is...
Add TFormData generic parameter to formOptions function
Add test to verify listener type preservation with formOptions
Current implementation has intentional type issues for investigation
deep-jadeOP•3w ago
lgtm!
Im not sure what this PR improves in this example.
flat-fuchsia•3w ago
in this example, nothing. However, as soon as you attempt to add listeners and validators, the difference will show up
if you don't use either one of those, then you needn't try the PR version
deep-jadeOP•3w ago
Thank you for your help
are you posting on bsky? you've been very helpful on every questions I had, I'm sure what you post would interest me!
flat-fuchsia•3w ago
no bsky, linkedin or twitter, I‘m afraid! I‘ve been mostly active on Discord since about 2018