Skip to main content

okAsync()

okAsync<T, E>(value): ResultAsync<T, E>

Creates a new successful async result.

This function wraps a value in a successful ResultAsync. If you need to wrap a Promise, use fromSafePromise or fromPromise instead.


Type Parameters​

T: T​

The type of the success value

E: E = never​

The type of the error value (defaults to never)


Parameters​

value: T​

The value to wrap


Returns: ResultAsync<T, E>​

A new ResultAsync that will resolve to Ok(value)


Since​

2.0.0


Example​

// With direct value
const direct = okAsync(42);
const resolved = await direct; // Ok(42)

// For Promises, use fromSafePromise or fromPromise
const promise = Promise.resolve("hello");
const async = ResultAsync.fromSafePromise(promise);
const result = await async; // Ok("hello")