Skip to main content

ImplicitAllowedTypes TypeAlias

Types of TreeNodes or TreeLeafValues allowed at a location in a tree.

Signature

export type ImplicitAllowedTypes = AllowedTypes | TreeNodeSchema;

Remarks

Used by TreeViewConfiguration for the root and various kinds of TreeNodeSchema to specify their allowed child types.

Use SchemaFactory to access leaf schema or declare new composite schema.

Implicitly treats a single type as an array of one type.

Arrays of schema can be used to specify multiple types are allowed, which result in unions of those types in the Tree APIs.

When saved into variables, avoid type-erasing the details, as doing so loses the compile time schema awareness of APIs derived from the types.

When referring to types that are declared after the definition of the ImplicitAllowedTypes, the schema can be wrapped in a lambda to allow the forward reference. See ValidateRecursiveSchema for details on how to structure the ImplicitAllowedTypes instances when constructing recursive schema.

Usage

Example 1

Explicit use with strong typing

const sf = new SchemaFactory("myScope");
const childTypes = [sf.number, sf.string] as const satisfies ImplicitAllowedTypes;
const config = new TreeViewConfiguration({ schema: childTypes });

Example 2

Forward reference

const sf = new SchemaFactory("myScope");
class A extends sf.array("example", [() => B]) {}
class B extends sf.array("Inner", sf.number) {}