feat(typescript-types): Add KeyPath<T, Separator = '.'>
This commit is contained in:
9
packages/typescript-types/src/key-path.ts
Normal file
9
packages/typescript-types/src/key-path.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import type { If } from './if.js'
|
||||
import type { IsEmptyString } from './is-empty-string.js'
|
||||
|
||||
export type KeyPath<
|
||||
P extends string,
|
||||
Separator extends string = '.'
|
||||
> = P extends `${infer Key}${Separator}${infer Rest}`
|
||||
? [Key, ...KeyPath<Rest, Separator>]
|
||||
: If<IsEmptyString<P>, [], [P]>
|
||||
Reference in New Issue
Block a user