Skip to content

Commit

Permalink
fix: limit deep keys to depth: 10
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Sep 13, 2023
1 parent e4a4842 commit 5fe4bf4
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/table-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,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[]
? never & 'Dynamic length array indexing is not supported'
: 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 5fe4bf4

Please sign in to comment.