The Struct Proxy Methods Struct.*() Parameters 1. schema 2. parents Examples Creating new concrete types Version History See also

The Struct Proxy

import { Struct } from "@fed1/jsos";

The Struct proxy creates new data types that can be instantiated using their .new() constructor method.

Objects instantiated from a type defined by using Struct are immutable, meaning their values can't change once the object has been created.

To create mutable objects, use the MStruct proxy instead to define your new type.

There is no TStruct type. This is by design. Structs are a way to create new complex types in JSOS's type graph, not just object creation facilities.

Methods

Struct.*()

A "magic method" that creates a new TDataType with an internal name of whatever is used in place of *.

Struct.*(schema, parents)

Parameters

# Parameter Required? Type Description
1 schema yes JSObject A schema describing the struct's properties and their types
2 parents no JSArray<TType> The type object's parents
1. schema

A JSObject that describes the structure of objects created by this struct. Its keys correspond to properties of the resulting object. The values are TType objects to determine the allowed type of values in the object that can be created from the struct.

2. parents

An optional array containing one or more parent type objects. The new type will be a child of these parents in the type hierarchy. The parent types must be abstract types. If the argument isn't provided, the new type will be a child of the hierarchy root TAny.

Examples

Creating new concrete types

Version History

Feature Since version
Struct.*() 1.0

See also