TanStack / TanStack/form

Recursive type, breaks the typesafety

Open
#1,553 1 comment 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: enhancement v1 v2
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.