Recursive type, breaks the typesafety
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 6.7k
- Forks
- 682
- Avg merge
- 5d 18h
- Merged PRs (30d)
- 7
Description
Describe the bug
If I have an object, that can reference itself. It will break the type-safety of the form.
For example here the list is any, and the function getFieldValue or the property name on Field does not have any type safety either.
type Name = {
name: string;
list: Name[];
};
const Component = () => {
const form = useForm({
defaultValues: {
name: "test",
list: [],
} as Name,
});
const list = form.getFieldValue("list");
return <div></div>;
};
Your minimal, reproducible example
check the description
Steps to reproduce
Create a form like I showed in the example.
Expected behavior
I would expect the list variable to be of type Name[] and name property etc... would remain type safe.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
- linux
- chrome
TanStack Form adapter
None
TanStack Form version
1.11.1
TypeScript version
5.8.3
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the TypeScript example in the issue and inspect the types behind useForm, getFieldValue, and Field. Verify the recursive Name shape in TypeScript 5.8.3, then confirm that list is inferred as Name[] and nested properties remain type-safe.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100