Skip to content
Source
Sign inSign up
TanStack/form

Recursive type, breaks the typesafety #1553

Openallan-from-meiro(GitHub profile, opens in a new tab) opened this issue 1 comment

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

  1. julienmonnard(GitHub profile, opens in a new tab)commented

    Hello! It seems MomentJS is also affected by this. Based on this discussion on Discord, the reproduction is as simple as

    import { type DeepKeys } from '@tanstack/react-form'
    import { type Moment } from 'moment'
    
    const test: DeepKeys<Moment> = ""

    It was tested with @tanstack/react-form@1.19.1 and typescript@5.8.3

  2. LeCarbonator(GitHub profile, opens in a new tab) added labelstype: enhancement

Sign in to join this conversation.