Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Type<T>

Simple type interface.

This is the smallest interface for objects to be valid types. A type with this interface can check the validity and equality of values, and clone them.

Type parameters

  • T

Hierarchy

Implemented by

Index

Properties

Methods

Properties

Optional name

name: undefined | string

Name of this type. This is only used to help with debugging.

Methods

clone

  • clone(value: T): T
  • Returns a deep copy of value.

    Parameters

    • value: T

      The value to clone, trusted to be compatible with this type.

    Returns T

    A deep copy of the supplied value, restricted to the properties of this type.

equals

  • equals(left: T, right: T): boolean
  • Tests if left is equal to value.

    This is a deep strict structural equality test restricted to the properties of this type.

    It satisfies the following properties (the variables a, b and c are valid values):

    • Reflexivity: type.equal(a, a) === true
    • Symmetry: type.equals(a, b) === type.equals(b, a)
    • Transitivity: if type.equals(a, b) && type.equals(b, c) then type.equals(a, c)

    The above properties mean that type objects implement the Setoid algebra as specified by Static Land.

    see

    https://github.com/rpominov/static-land/blob/master/docs/spec.md#setoid

    Parameters

    • left: T

      Left value, trusted to be compatible with this type.

    • right: T

      Right value, trusted to be compatible with this type.

    Returns boolean

    Boolean indicating if both values are equal.

Optional lte

  • lte(left: T, right: T): boolean
  • Compares two valid values.

    Parameters

    • left: T

      Left operand, a valid value.

    • right: T

      Right operand, a valid value.

    Returns boolean

    Boolean indicating if left <= right is true.

Optional read

  • read<R>(reader: Reader<R>, input: R): T
  • Deserializes a value of this type.

    Type parameters

    • R

    Parameters

    • reader: Reader<R>

      Reader to drive during the deserialization.

    • input: R

      Reader input.

    Returns T

    Valid value.

test

  • test(value: T): boolean
  • Tests if this type matches value.

    Parameters

    • value: T

      The value to test against this type.

    Returns boolean

    Boolean indicating if this type matches value.

Optional testError

  • testError(value: T): Error | undefined
  • Tests if this type matches value, describes the error if not.

    Parameters

    • value: T

      The value to test against this type.

    Returns Error | undefined

    If this type matches value then undefined; otherwise an error describing why this type does not match value.

Optional write

  • write<W>(writer: Writer<W>, value: T): W
  • Serializes the valid value value.

    Type parameters

    • W

    Parameters

    • writer: Writer<W>

      Writer used to emit the data.

    • value: T

      Value to serialize.

    Returns W

    Writer result.

Generated using TypeDoc