Skip to content

Latest commit

 

History

History
43 lines (31 loc) · 687 Bytes

File metadata and controls

43 lines (31 loc) · 687 Bytes

typelab / utils / ObjectPath

type ObjectPath<T> = IsObjectLiteral<T> extends true ? { [K in keyof T]-?: K extends Exclude<PropertyKey, symbol> ? `${K}` | `${K}.${ObjectPath<T[K]>}` : never }[keyof T] : never;

Get all of the paths from T as a string union.

Type Parameters

Type Parameter Description

T

The object type to extract paths from.

Returns

A string union of paths in the object.

Example

type Obj = { a: { b: number }; c: string };
type Paths = ObjectPath<Obj>; // "a" | "a.b" | "c"