Skip to content
Source
Sign inSign up
TanStack/form

fix(form-core): stop DeepKeys and DeepValue expansion on self-referencing types #2422

Openmusatoktas(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/2422/headopened

Showing 3 changed files with 73 additions and 7 deletions (loading 1).

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/calm-keys-stop.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/form-core': patch
+---
+​
+Fix `DeepKeys` and `DeepValue` failing with "Type instantiation is excessively deep and possibly infinite" (TS2589) for self-referencing types such as recursive JSON types. Expansion of a path now stops when a container type repeats on the path, and the remaining path is typed as an unknown accessor that also accepts consecutive array indexes such as `data[0][0]`. Types without self-references are unchanged.
68 additions and 7 deletionspackages/form-core/src/util-types.tsModified
View file
@@ -59,10 +59,12 @@
TParent extends AnyDeepKeyAndValue,
T extends ReadonlyArray<any>,
TAcc,
+ TVisited = never,
> = DeepKeysAndValuesImpl<
NonNullable<T[number]>,
ArrayDeepKeyAndValue<TParent, T>,
- TAcc | ArrayDeepKeyAndValue<TParent, T>
+ TAcc | ArrayDeepKeyAndValue<TParent, T>,
+ TVisited | T
​
export type TupleAccessor<
@@ -86,11 +88,13 @@
T extends ReadonlyArray<any>,
TAcc,
TAllKeys extends AllTupleKeys<T> = AllTupleKeys<T>,
+ TVisited = never,
> = TAllKeys extends any
? DeepKeysAndValuesImpl<