Skip to main content

Tag

Index

Interfaces

Functions

Interfaces

Module

  • Module(value: From): To
  • Convert an underlying type to a tagged type Alias to wrap(value)

typeName

Re-exports typeName

__call__

__call__: (value: From) => To

Callable property

inspect

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

When defined, returns a custom string representation

@example

@param

asInstance

  • asInstance(anyValue: unknown): Option<To>
  • 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

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: To): 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);

hasInstance

  • hasInstance(anyValue: unknown): anyValue is To
  • 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

unwrap

  • unwrap(value: To): From
  • Convert a tagged value to the underlying type

wrap

  • wrap(value: From): To
  • Convert an underlying type to a tagged type

Parameters

Parameters<T>:

Type module constructor parameters


Type parameters

  • T

optionalasInstance

asInstance?: (anyValue: unknown) => Option<T>

hasInstance

hasInstance: (value: unknown) => boolean

optionalinspect

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

typeName

typeName: string

optionalcodecDecode

  • 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);

optionalcodecEncode

  • codecEncode(this: void, input: 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);

optionalcodecSchema

  • Returns the JSONSchema corresponding to the decoded type

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

Functions

define

  • Returns a new Tag module

    @example
    type Foo = string & Tag<'Foo'>;
    const Foo = Tag.define<string, Foo>({
    typeName: 'Foo',
    hasInstance: (anyValue) => typeof anyValue === 'string',
    });

    Type parameters

    • From
    • To
Page Options