The Type Proxy
import { Type } from "@fed1/jsos";
The Type proxy creates and assigns new abstract types.
Usage
const { TMyType } = Type;
const { TMyType } = Type(...parents);
const { TMyType } = Type(...parents)(root);
const { TMyType } = Type(...parents)(root)(options);
Abstract type names must start with
T, if they don't, an error is thrown. This naming scheme is enforced to make the JSOS ecosystem more cohesive.
Parameters
| # | Parameter | Required? | Type | Default |
|---|---|---|---|---|
| 1 | parents | no | JSArray<TType> | [TAny] |
| 2 | root | no | TType | TAbstractType |
| 3 | options | no | JSObject |
1. parents
An 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.
2. root
The meta type of the type to be created. This is what's returned when using typeOf() on the type.
3. options
An options object with these properties:
covariant: AJSBooleandefaulting tofalse. Set this totrueif you want your type to be covariant in type comparisons.
Examples
Creating new abstract types
The following creates a new abstract type called TMyType that is a subtype
of TComposite.
import { Type, TComposite } from "@fed1/jsos";
const { TMyType } = Type(TComposite);
Version History
| Feature | Since version |
|---|---|
| Type | 1.0 |
See also
- Article: The JSOS Type System
