Skip to main content

Enumerable <T>

A type that represents a class module of T instances

Hierarchy

Index

Codec

codecDecode

  • Returns the decoded input, Result.Ok or Result.Error()

    @example
    interface SomeObject {
    foo: string
    }
    const someCodec: Codec<SomeObject> = ...;
    const input: unknown = ...;
    const decoded = Codec.decode(someCodec, input);

codecEncode

  • codecEncode(this: void, input: T[keyof T]): unknown
  • Returns the encoded input

    @example
    interface SomeObject {
    foo: string
    }
    const someCodec: Codec<SomeObject> = ...;
    const someObject: SomeObject = { foo: "bar" }
    const encoded = Codec.decode(someCodec, someObject);

codecSchema

  • Returns the JSONSchema corresponding to the decoded type

    @example
    const someCodec: Codec<unknown> = ...;
    const jsonSchema = Codec.schema(someCodec);

Constructor

asInstance

  • asInstance(anyValue: unknown): Option<T[keyof T]>
  • 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

Type

inspect

inspect: Option<(anyValue: T[keyof T], depth: number, options: InspectOptions, inspect: InspectFunction) => string>

When defined, returns a custom string representation

@example

@param

hasInstance

  • hasInstance(anyValue: unknown): anyValue is T[keyof T]
  • 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

typeName

Re-exports typeName

readonly[w5s.enumKeys]

[w5s.enumKeys]: readonly keyof T[]

An array of all keys

indexType

indexType: number

Index type

at

  • at(index: number): Option<T[keyof T]>
  • Returns the value at the index

indexOf

  • indexOf(value: T[keyof T]): Option<number>
  • Returns the integer index of a value

range

  • range(start: T[keyof T], end: T[keyof T]): Range<T[keyof T]>
  • Returns an Iterable starting from start to end. If start or end is not in range then returns an empty iterable.

rangeSize

  • rangeSize(start: T[keyof T], end: T[keyof T]): number
  • Returns the size of a range. If start or end is not in range then returns 0.