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

    Class Err<T>

    Represents a failed operation with one or more structured issues.

    Type Parameters

    • T

      The type that would have been returned if successful

    Index

    Constructors

    Properties

    Methods

    Constructors

    • Creates a new Err instance from structured decoding issues.

      Type Parameters

      • T

        The type that would have been returned if successful

      Parameters

      • issues: readonly DecodingIssue[]

        The list of issues describing what went wrong and where.

      Returns Err<T>

    Properties

    issues: readonly DecodingIssue[]

    The list of issues describing what went wrong and where.

    Methods

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

      Returns this is Ok<T>

      false for Err instances

      const result: Result<number> = err([{ message: "Invalid input", path: [] }]);
      if (!result.isOk()) {
      // TypeScript knows result.issues exists here
      console.log(result.issues);
      }
    • Returns a new Err with the same issues but a different type parameter. Since this represents an error, the transform function is never called.

      Type Parameters

      • O

        The new type parameter

      Parameters

      • _fn: (value: T) => O

        The function that would have transformed the value (ignored)

      Returns Result<O>

      A new Err with the same issues

      const result: Result<number> = err("Invalid input");
      const mapped: Result<string> = result.map(x => x.toString());
      // mapped = Err([{ message: "Invalid input", path: [] }])