Describe the bug
The library cannot infer the right type of fields in a (probably weird) edge case, when an array is an union type of objects.
Take this as example:
type Text = {
type: 'text';
answer: string;
textAnswer: string;
};
type Number = {
type: 'number';
answer: number;
};
type FormType = {
questions: Array<Text | Number>
}
When accessing to questions[0].answer (field in both types) the type is string | number.
When accessing to questions[0].textAnswer (field on one type only) the type is unkown
Your minimal, reproducible example
https://stackblitz.com/edit/tanstack-form-ydorgn?file=src%2Findex.tsx%3AL53-L53
Steps to reproduce
- Have a structure with an array of union of objects
- Use field.state in jsx
Expected behavior
Not sure if it's a bug or a missing feature, but I'd like a way to know which is the correct type of the array entry and have all the fields typed accordingly.
The form is handling the values right, typescript isn't.
See the MRE for more comments.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
macOS
TanStack Form adapter
react-form
TanStack Form version
v0.19.4
TypeScript version
No response
Additional context
No response
Describe the bug
The library cannot infer the right type of fields in a (probably weird) edge case, when an array is an union type of objects.
Take this as example:
When accessing to
questions[0].answer(field in both types) the type isstring | number.When accessing to
questions[0].textAnswer(field on one type only) the type isunkownYour minimal, reproducible example
https://stackblitz.com/edit/tanstack-form-ydorgn?file=src%2Findex.tsx%3AL53-L53
Steps to reproduce
Expected behavior
Not sure if it's a bug or a missing feature, but I'd like a way to know which is the correct type of the array entry and have all the fields typed accordingly.
The form is handling the values right, typescript isn't.
See the MRE for more comments.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
macOS
TanStack Form adapter
react-form
TanStack Form version
v0.19.4
TypeScript version
No response
Additional context
No response