How do you manage fields with the type `Record<string, ...>` ?
I wonder if it is possible to have such field value with TanStack Form. Pretty sure it should (and is) but the types seem wrong:
In this example, I specify the field name where
home
is a variable in my real use case.
If you open this Stackblitz repro, you'll notice this does not work as expected:
https://stackblitz.com/edit/ts-form-object?file=src%2Findex.tsx&preset=node
There is no type issue on the name
attribute of form.Field
as it respect one of the expected value (address.${string}.street
), although the type of the value itself is wrong:
So is the handleChange
definition.
Am I doing something wrong? Is it not supported (and therefore should I need to change the structure of my form)?Benjamin
StackBlitz
TSF Object - StackBlitz
Run official live example code for Form Simple, created by Tanstack on StackBlitz
20 Replies
fascinating-indigoOP•3mo ago
This "works":
It seems the
value
and handleChange
types match the first ${string}
occurrence. Not sure if this is expected.national-gold•3mo ago
Records should be supported, and that type looks wrong.
address.${'home'}.street
should be a valid template string to enterfascinating-indigoOP•3mo ago
mmh
does the Stackblitz highlights an issue then ?
national-gold•3mo ago
I'll take a look. The stackblitz seems short enough, so a unit test should be easy to derive
fascinating-indigoOP•3mo ago
awesome
if required i can open an issue on github for you
national-gold•3mo ago
this bug seems familiar ... the intersection with string I mean
fascinating-indigoOP•3mo ago
yeah the intersection with both the type of address.home and address.home.street looks suspicious ;D
national-gold•3mo ago
maybe it's solid-specific. I just checked my React prod implementation using a record and the type is just fine there
national-gold•3mo ago
nope, it's not. Could you create a Github issue with your stackblitz reproduction, please? @binajmen

fascinating-indigoOP•3mo ago
sure I will !
fascinating-indigoOP•3mo ago
GitHub
Records fields have wrong types · Issue #1551 · TanStack/form
Describe the bug I wonder if it is possible to have such field value with TanStack Form. Pretty sure it should (and is) but the types seem wrong: function App() { const form = createForm(() => (...
fascinating-indigoOP•3mo ago
(I wasn't inspired for the name of the issue, sorry ^^)
national-gold•3mo ago
thanks!
fascinating-indigoOP•3mo ago
you're welcome, thank YOU for the nice work !
national-gold•3mo ago
took some time analyzing this. The main issue is that TypeScript sees
foo.${string}.bar
as matching both foo.${string}.bar
as well as foo.${string}
so any subfield from a record gets caught in an intersection with the record valuefascinating-indigoOP•3mo ago
yeah that's what I noticed
you are mentioning typescript. does it means it's not solvable with the current typescript implementation?
national-gold•3mo ago
no, it needs fixing the types
fascinating-indigoOP•3mo ago
I can live with the type issue. my understanding is that the functionality itself exists in TS Form, which is good enough for me 😉
I can just cast for the time being
national-gold•3mo ago
the reason it wasn't caught is because the iteration doesn't throw a type error, even though the type it generated can't be created
For reference:
fascinating-indigoOP•3mo ago
han