feat(typescript-types): Add KeyPath<T, Separator = '.'>

This commit is contained in:
T. R. Bernstein
2025-07-15 07:44:21 +02:00
parent 0cbc6d41a4
commit eac7768bfb
3 changed files with 26 additions and 0 deletions

View 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]>