Skip to main content

Struct

Index

Constructor

Module

  • Construct a new model

__call__

__call__: (properties: Parameters<Model>) => Model

Callable property

inspect

inspect: Option<(anyValue: Model, depth: number, options: InspectOptions, inspect: InspectFunction) => string>

When defined, returns a custom string representation

@example

@param

readonlytypeName

typeName: Model[_]

The factory type constant

asInstance

  • asInstance(anyValue: unknown): Option<Model>
  • Try to convert anyValue to enum value or else returns Option.None

    @example
    const StringType: Type<string>;
    StringType.asInstance('foo'); // Option.Some('foo')
    StringType.asInstance(12); // Option.None

create

  • create(this: void, properties: Parameters<Model>): Model
  • Construct a new model

hasInstance

  • hasInstance(anyValue: unknown): anyValue is Model
  • Return true if the given value is an instance of the class.

    @example
    const StringType: Type<string>;
    StringType.hasInstance('foo'); // true
    StringType.hasInstance(42); // false

Other

Parameters

Parameters<Model>: Omit<Model, Struct.type>

Extract all parameters to create a new Struct


Type parameters

  • Model

type

type: typeof type

consttype

type: _ = '_'

The type property discriminator

define

  • define<Model>(typeName: Model[_]): Module<Model>
  • Return a new Struct default factory See Module for additional properties added to the constructor

    @example
    type Model = Struct<{ [Struct.type]: 'Model', foo: boolean }>
    const Model = Struct.define<Model>('Model');

    const instance = Model({ foo: true }); // { _: 'Model', foo: true }
    Model.typeName === 'Model' // true
    Model.hasInstance(instance); // true

    Type parameters

    • Model: Readonly<{ _: string }>
Page Options