Recursive type, breaks the typesafety

オープン
#1,553 コメント 1 件 リアクション 9 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
38/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
typescript
領域
frontend

調査の方向性

Issue の TypeScript の例から始め、useForm、getFieldValue、Field の背後にある型を調べてください。TypeScript 5.8.3 で再帰的な Name の形状を検証し、その後、list が Name[] として推論され、ネストされたプロパティが引き続き型安全であることを確認してください。

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
TypeScript
スター
6.8k
フォーク
717
平均マージ
5日 22時間
マージ済み PR(30日)
14

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

TanStack/form のほかの issue

TanStack/form の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。