ts.data.json - v4.1.0
    Preparing search index...

    Class Ok<T>

    A type-safe way to handle success and error cases. The Result type is used throughout the library to handle decoding results.

    Type Parameters

    • T

      The type of the successful value

    Index

    Constructors

    Properties

    Methods

    Constructors

    • Creates a new Ok instance containing a successful value.

      Type Parameters

      • T

        The type of the successful value

      Parameters

      • value: T

        The successful value

      Returns Ok<T>

    Properties

    value: T

    The successful value

    Methods

    • Type guard to check if this Result is an Ok. Always returns true for Ok instances.

      Returns this is Ok<T>

      true for Ok instances

      const result: Result<number> = ok(5);
      if (result.isOk()) {
      // TypeScript knows result.value exists here
      console.log(result.value);
      }
    • Transforms the successful value using the provided function. If this is an Ok, applies the function to the value and wraps the result in a new Ok.

      Type Parameters

      • O

        The type of the transformed value

      Parameters

      • fn: (value: T) => O

        The function to transform the value

      Returns Result<O>

      A new Result containing the transformed value

      const result: Result<number> = ok(5);
      const doubled: Result<number> = result.map(x => x * 2);
      // doubled = Ok(10)