(x: unknown): x is {
readonly key: string
readonly members: Record<string, unknown>
}Whether x is a group tag (vs a leaf resource tag) — the discriminator for walking a tree.
Tags are classes (so typeof is "function", not "object"); a group is one carrying a
members record. Use it to recurse on branches and treat everything else as a leaf:
for (const [name, member] of Object.entries(Group.members(node)))
Group.isGroup(member) ? walk(member) : renderLeaf(name, member);guards
Source src/Group.ts:714 lines
export const const isGroup: (x: unknown) => x is {
readonly key: string
readonly members: Record<string, unknown>
}
Whether x is a group tag (vs a leaf resource tag) — the discriminator for walking a tree.
Tags are classes (so typeof is "function", not "object"); a group is one carrying a
members record. Use it to recurse on branches and treat everything else as a leaf:
for (const [name, member] of Object.entries(Group.members(node)))
Group.isGroup(member) ? walk(member) : renderLeaf(name, member);
isGroup = (
x: unknownx: unknown,
): x: unknownx is { readonly key: stringkey: string; readonly members: Record<string, unknown>members: type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<string, unknown> } =>
(typeof x: unknownx === "object" || typeof x: {} | undefinedx === "function") && x: object | nullx !== null && "members" in x: objectx;