`withForm` and `withFieldGroup` types for `render` and `props`
I have 2 questions.
Question 1
Is there any reason why
TRenderProps in withForm and withFieldGroup are different?
Current state:
withForm: TRenderProps extends object = Record<string, never>
withFieldGroup: TRenderProps extends Record<string, unknown> = Record<string, never>
My use-case:
Question 2
Is there any reason why the return type of render is JSX.Element only instead of ReactNode for example?
My use-case:
I can do return <></> and that fixes it, but still...13 Replies
sunny-green•2mo ago
The reason they're different is because
withFieldGroup missed out on a fix for withForm regarding TRenderProps.
The fix was for assigning interfaces as props, which isn't possible with Record<string, unknown> because interfaces have no index signature.
As for the return type in render, it's typed as React.FunctionComponent<TProps>. Apparently, React restricts that to Jsx.Element instead of ReactNode.
So for that:
sunny-green•2mo ago
GitHub
withFieldGroup#props does not support interfaces · Issue #1703 ...Describe the bug withForm has initially had the same issue, where interfaces are not assignable to Record<string, unknown>. This is because interfaces do not have an index signature. #1601 (a...
sunny-green•2mo ago
the first one has the issue above assigned. As for the render one, AFAIK
Jsx.Element is a subset of ReactNode, so it wouldn't be a breaking change to widenitchy-amethystOP•2mo ago
maybe I'm mistaken, but you seem to specify
JSX.Element here whereas you could use ReactNode.
https://github.com/TanStack/form/blob/6d25ea10035a62c0bf1b8154c9b9551d699b6097/packages/react-form/src/createFormHook.tsx#L244
And yes, it's a wider type, so shouldn't be breaking.GitHub
form/packages/react-form/src/createFormHook.tsx at 6d25ea10035a62c0...
🤖 Headless, performant, and type-safe form state management for TS/JS, React, Vue, Angular, Solid, and Lit. - TanStack/form
sunny-green•2mo ago
oh. Guess I was wrong about that assumption then.
It's probably in more locations than just that one, but it's not a big deal to widen. Is there an issue for this yet?
itchy-amethystOP•2mo ago
I don't think so, at least I haven't found it, when I looked for it initially before posting the question.
sunny-green•2mo ago
would you mind making one? Feel free to link #1703 to it because both have to do with widening the generics
itchy-amethystOP•2mo ago
I can make 2 PRs tomorrow for the issue above and this one, if you'd like.
sunny-green•2mo ago
we're open for PRs, and I'd gladly CR it if you'd make one. I can look up the reference for the
withForm fix in a sec
https://github.com/TanStack/form/pull/1601
if you're too busy for it, I'll probably make a PR on thursdayitchy-amethystOP•2mo ago
I'll make the issue and the PRs tomorrow, but I have to leave now unfortunately. Thank you for your answers.
sunny-green•2mo ago
no worries. Thanks for reaching out!
itchy-amethystOP•2mo ago
FYI:
https://github.com/TanStack/form/issues/1815
https://github.com/TanStack/form/pull/1816
https://github.com/TanStack/form/pull/1817
GitHub
Return type of
render is unnecessarily strict in withForm and `...Describe the bug Related: #1703 The return type of render in withForm and withFieldGroup is JSX.Element only instead of ReactNode. This makes it impossible to do and early return null for example a...
GitHub
fix(react-form): allow interfaces to be assigned to `withFieldGroup...
Fixes: #1703
🎯 Changes
This PR fixes an issue that the previous generic had for interfaces in TypeScript similarly to #1601.
The purpose and the implementation is exactly the same, but now for with...
GitHub
fix(react-form): widen return type of render prop by xotea · Pull ...
Fixes: #1815
🎯 Changes
In React JSX.Element is only a subset of the valid children described by ReactNode. By widening this type we allow returning all valid React children now in a non-breaking fa...
sunny-green•2mo ago
awesome, thanks a lot! I'll look at them this evening