Type alias Branches<Target>

Branches<Target>: Target extends unknown[]
    ? ""
    : Target extends object
        ? Replace<_Branches<Target>, ".", "", false>
        : ""

Branches

Type Parameters

  • Target

    The object to get the branches of

Desc

Get all possible branches of an object in dot & bracket notation

Returns

All possible branches of the object

Example

type Sample = {
a: string;
b: {
c: string;
d?: {
e?: string;
f: Array<{
g: string;
h: {
i?: string;
};
}>;
};
};
}
type Result = Branches<Sample>; // 'a' | 'b' | 'b.c' | 'b.d' | 'b.d.e' | 'b.d.f' | 'b.d.f[number].g' | 'b.d.f[number].h' | 'b.d.f[number].h.i'