Readonly_Readonly[toReadonlyerrorThe error of a Failure; undefined on a Success
ReadonlyvalueThe value of a Success; undefined on a Failure
Tests whether the success value, if there is one, satisfies the predicate. The dual of
exists, and Scala's forall: with no success value it gives true, as [].every(p) does.
Returns the success value, or calls the never-returning handler with the Failure's error.
Use this when you have a helper like (msg) => fail(msg, 2) that terminates the program —
the result type is unconditionally T, so you avoid the TypeScript narrowing trap where
if (t.isFailure()) fail(...) fails to narrow t.value when fail is an arrow function
typed as (...): never.
Applies a predicate to the success value. If the predicate fails, short-circuits
to a Failure with the error produced by onUnsatisfied. Failure passes through
unchanged (predicate not evaluated). Lets you turn a value-level guard into the
error channel without writing a manual throw inside a Try(() => ...) body.
A Success if the predicate holds, a Failure carrying onUnsatisfied(value) otherwise
Pattern matches over the Try, applying onFailure if Failure and onSuccess if Success
The result of applying the appropriate function
Pattern matches over the Try, applying a handler function based on the variant
The result of applying the matching handler function
Returns the value, or throws on a Failure. Pass an Error to throw it, or a builder to make one from
the failure's error. With no argument, rethrows the original error.
Optionalerror: Error | ((error: Error) => Error)Recovers from a Failure by applying a function to the error, returning a new Try.
The recovery value may be a wider type; the result is Try<T | U>, matching
Scala's recover[U >: T] shape so Try stays covariant in T.
Converts to a plain readonly array: [value] for Success, [] for Failure.
Symmetric with Try.toList() but skips the List wrapper for code that
just wants to feed Array.prototype methods or spread into another array.
Converts to Either<E, T>. Failure becomes Left(builder(error)) when given a function, or Left(leftValue) when given a value. Success becomes Right(value).
Prefer the function form to thread the underlying Error's context into the Left:
Try(() => JSON.parse(text)).toEither((e) => parse failed: ${e.message})
Custom JSON serialization. Success emits {"@functype":"Try","_tag":"Success","value":T}.
Failure emits {"@functype":"Try","_tag":"Failure","error":SerializedError} where
SerializedError captures name, message, stack, and the full cause chain —
e.name survives round-trip but instanceof SomeError does not.
Converts this container to a Promise
The behavior depends on the implementing container:
A Promise that resolves or rejects based on the container's state
Returns a string representation of an object.
Converts this monad to a Try.
Conversion rules:
A Try containing Success with the value or Failure with an appropriate error
What every Try has, Success or Failure.
Try<T>is the union ofSuccessOf<T>andFailureOf<T>, so TypeScript narrows it onisSuccess(),isFailure()and_tag, as it does Either.