mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 18:01:06 +00:00
Co-authored-by: K.Kiyokawa <koichi20110068@gmail.com> Co-authored-by: brunnerh <brunnerh@users.noreply.github.com>
18 lines
485 B
TypeScript
18 lines
485 B
TypeScript
type PathDepth = [never, 0, 1, 2, ...0[]];
|
|
|
|
type Join<K, P> = K extends string | number
|
|
? P extends string | number
|
|
? `${K}${"" extends P ? "" : "."}${P}`
|
|
: never
|
|
: never;
|
|
|
|
// For performance, the maximum traversal depth is 10.
|
|
export type PropertyPath<T, D extends number = 10> = [D] extends [never]
|
|
? never
|
|
: T extends object
|
|
? {
|
|
[K in keyof T]-?: K extends string | number
|
|
? `${K}` | Join<K, PropertyPath<T[K], PathDepth[D]>>
|
|
: never;
|
|
}[keyof T]
|
|
: "";
|