Skip to content

Commit

Permalink
fix: limit deep keys to max depth of 10
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Sep 13, 2023
1 parent 658c8f8 commit 46b49ca
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/form-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,28 @@ type AllowedIndexes<
? AllowedIndexes<Tail, Keys | Tail['length']>
: Keys

export type DeepKeys<T> = unknown extends T
export type DeepKeys<T, TDepth extends any[] = []> = TDepth['length'] extends 10
? never
: unknown extends T
? keyof T
: object extends T
? string
: T extends readonly any[] & IsTuple<T>
? AllowedIndexes<T> | DeepKeysPrefix<T, AllowedIndexes<T>>
? AllowedIndexes<T> | DeepKeysPrefix<T, AllowedIndexes<T>, TDepth>
: T extends any[]
? DeepKeys<T[number]>
: T extends Date
? never
: T extends object
? (keyof T & string) | DeepKeysPrefix<T, keyof T>
? (keyof T & string) | DeepKeysPrefix<T, keyof T, TDepth>
: never

type DeepKeysPrefix<T, TPrefix> = TPrefix extends keyof T & (number | string)
? `${TPrefix}.${DeepKeys<T[TPrefix]> & string}`
type DeepKeysPrefix<
T,
TPrefix,
TDepth extends any[],
> = TPrefix extends keyof T & (number | string)
? `${TPrefix}.${DeepKeys<T[TPrefix], [...TDepth, any]> & string}`
: never

export type DeepValue<T, TProp> = T extends Record<string | number, any>
Expand Down

0 comments on commit 46b49ca

Please sign in to comment.