--- layout: home hero: name: results-ts text: Rust's Result and Option types, for TypeScript. tagline: Chain operations on values, errors, and optional values. actions: - theme: brand text: Get started link: /guide/getting-started - theme: alt text: API reference link: /api/ - theme: alt text: Benchmarks link: https://github.com/madkarmaa/results-ts/blob/main/BENCHMARKS.md --- # Guide Use [`Result`](../api/type-aliases/Result.md) for operations that return a value or an error. Use [`Option`](../api/type-aliases/Option.md) for values that may be absent. - [Getting started](./getting-started.md) covers installation and examples of both types. - [Error handling](./error-handling.md) explains panics, invalid arguments, and [`catchUnwind`](../api/functions/catchUnwind.md). - [Async support](./async.md) explains how to chain and await async results and options. # Getting started Install `results-ts`, then use [`Result`](../api/type-aliases/Result.md) for errors or [`Option`](../api/type-aliases/Option.md) for optional values. ## Installation ```bash bun add results-ts # or npm install results-ts # or pnpm add results-ts # or deno add results-ts # or yarn add results-ts ``` ### Browser without a bundler This library is an ES module. To use it directly in a browser, import it from a CDN inside a ` ``` ## Core concepts Use [`Result`](../api/type-aliases/Result.md) when a failed operation needs an error value. Use [`Option`](../api/type-aliases/Option.md) when a value may be absent and you do not need an error value. ## Result [`Result`](../api/type-aliases/Result.md) is either [`Ok(value)`](../api/functions/Ok.md) with a value of type `T`, or [`Err(error)`](../api/functions/Err.md) with an error of type `E`. Return a [`Result`](../api/type-aliases/Result.md) when callers can recover from a failure. ```typescript import { Ok, Err } from 'results-ts'; const parseUserId = (id: string) => { const parsed = parseInt(id, 10); if (isNaN(parsed)) return Err({ code: 'INVALID_INPUT', message: 'ID must be a valid number' } as const); if (parsed <= 0) return Err({ code: 'INVALID_ID', message: 'ID must be positive' } as const); return Ok(parsed); }; const fetchUser = (id: number) => { if (id === 13) return Err({ code: 'NOT_FOUND', message: 'User not found' } as const); return Ok({ id, name: 'Alice', role: 'admin' }); }; const message = parseUserId('10') .map((id) => id + 3) .andThen(fetchUser) .match({ Ok: (user) => `Welcome, ${user.role} ${user.name}!`, Err: (error) => { if (error.code === 'NOT_FOUND') return `Database Error: ${error.message}`; return `Validation Error: ${error.message}`; } }); ``` > [!NOTE] > [`Result.unwrap()`](../api/interfaces/ResultMethods.md#unwrap) and [`Result.expect()`](../api/interfaces/ResultMethods.md#expect) throw on `Err`. [`Result.unwrapErr()`](../api/interfaces/ResultMethods.md#unwraperr) and [`Result.expectErr()`](../api/interfaces/ResultMethods.md#expecterr) throw on `Ok`. Use [`Result.unwrapOr()`](../api/interfaces/ResultMethods.md#unwrapor), [`Result.unwrapOrElse()`](../api/interfaces/ResultMethods.md#unwraporelse), or [`Result.match()`](../api/interfaces/ResultMethods.md#match) for recoverable failures. See [Error handling](./error-handling.md). ## Option [`Option`](../api/type-aliases/Option.md) is either [`Some(value)`](../api/functions/Some.md) with a value of type `T`, or [`None()`](../api/functions/None.md) with no value. Use its methods to handle a value that may be absent. ```typescript import { Some, None } from 'results-ts'; const parseNickname = (nickname?: string) => { if (!nickname) return None(); const trimmed = nickname.trim(); return trimmed.length > 0 ? Some(trimmed) : None(); }; const displayName = parseNickname(' Ada ') .map((name) => name.toUpperCase()) .match({ Some: (name) => name, None: () => 'ANONYMOUS' }); ``` Call [`None()`](../api/functions/None.md) to create an absent value. Use [`None()`](../api/functions/None.md) to specify its type. Convert an [`Option`](../api/type-aliases/Option.md) to a [`Result`](../api/type-aliases/Result.md) with [`Option.okOr(err)`](../api/interfaces/OptionMethods.md#okor) or [`Option.okOrElse(() => err)`](../api/interfaces/OptionMethods.md#okorelse). ## Next steps - [Error handling](./error-handling.md) explains panics, invalid arguments, and [`catchUnwind`](../api/functions/catchUnwind.md). - [Async support](./async.md) covers [`AsyncResult`](../api/interfaces/AsyncResult.md) and [`AsyncOption`](../api/interfaces/AsyncOption.md). - [API reference](../api/index.md) documents each type and method. # Error handling Use [`Result`](../api/type-aliases/Result.md) for expected failures. Panic errors and argument validation errors indicate bugs in the calling code. ## Panics The following methods throw an internal `PanicError`. On async wrappers, they return a promise that rejects with that error: | Method | Panics when | | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | | [`Result.unwrap()`](../api/interfaces/ResultMethods.md#unwrap)
[`Option.unwrap()`](../api/interfaces/OptionMethods.md#unwrap)
[`AsyncResult.unwrap()`](../api/interfaces/AsyncResult.md#unwrap)
[`AsyncOption.unwrap()`](../api/interfaces/AsyncOption.md#unwrap) | the outcome is [`Err`](../api/functions/Err.md) or [`None`](../api/functions/None.md) | | [`Result.expect()`](../api/interfaces/ResultMethods.md#expect)
[`Option.expect()`](../api/interfaces/OptionMethods.md#expect)
[`AsyncResult.expect()`](../api/interfaces/AsyncResult.md#expect)
[`AsyncOption.expect()`](../api/interfaces/AsyncOption.md#expect) | the outcome is [`Err`](../api/functions/Err.md) or [`None`](../api/functions/None.md) | | [`Result.unwrapErr()`](../api/interfaces/ResultMethods.md#unwraperr)
[`AsyncResult.unwrapErr()`](../api/interfaces/AsyncResult.md#unwraperr) | the value is [`Ok`](../api/functions/Ok.md) | | [`Result.expectErr()`](../api/interfaces/ResultMethods.md#expecterr)
[`AsyncResult.expectErr()`](../api/interfaces/AsyncResult.md#expecterr) | the value is [`Ok`](../api/functions/Ok.md) | Use these methods only when an [`Err`](../api/functions/Err.md) or [`None`](../api/functions/None.md) would indicate a bug. For expected failures or absent values, use a fallback or handle each variant: - [`Result.unwrapOr(fallback)`](../api/interfaces/ResultMethods.md#unwrapor) and [`Option.unwrapOr(fallback)`](../api/interfaces/OptionMethods.md#unwrapor) return a default value. - [`Result.unwrapOrElse((err) => fallback)`](../api/interfaces/ResultMethods.md#unwraporelse) and [`Option.unwrapOrElse(() => fallback)`](../api/interfaces/OptionMethods.md#unwraporelse) compute a default only when needed. - [`Result.match({ Ok, Err })`](../api/interfaces/ResultMethods.md#match) and [`Option.match({ Some, None })`](../api/interfaces/OptionMethods.md#match) call a handler for the current variant. ```typescript import { Ok, Err } from 'results-ts'; // Return a fallback on Err. const n = Ok(1).unwrapOr(0); // 1 const m = Err('oops').unwrapOr(0); // 0 // Throw on Err. const k = Ok(1).unwrap(); // 1 const bad = Err('oops').unwrap(); // throws PanicError ``` ## Misuse errors Methods that accept callbacks or operands validate their types at runtime. Invalid arguments throw errors, including when untyped JavaScript or a type assertion bypasses TypeScript's checks. Fix the calling code when validation fails. ## Error classes are not exported The library does not export `PanicError`, `InvalidArgumentError`, or its other internal error classes. Use [`Result`](../api/type-aliases/Result.md) for expected failures and [`Option`](../api/type-aliases/Option.md) for absent values. ## Exception adapters Avoid [`catchUnwind`](../api/functions/catchUnwind.md) and [`catchUnwindAsync`](../api/functions/catchUnwindAsync.md). Use either only as a last resort when an external dependency or platform API inevitably throws or rejects, you cannot change that behavior, and no nonthrowing or [`Result`](../api/type-aliases/Result.md)-returning API is available. Some Node APIs require this exception. Do not use these adapters for code you control, routine failures, general `try`/`catch`, or just to create a [`Result`](../api/type-aliases/Result.md) or [`AsyncResult`](../api/interfaces/AsyncResult.md). Return [`Err`](../api/functions/Err.md) for recoverable failures in your own code, including invalid input and HTTP status failures. Keep any unavoidable adapter at the external call boundary, and use its `onThrow` handler to map the unknown thrown value to a specific error type. For reference, this is how to adapt a legacy boundary that must keep a throwing `JSON.parse` call: ```typescript import { catchUnwind } from 'results-ts'; const parseLegacyJson = catchUnwind( (text: string): unknown => JSON.parse(text), (thrown) => (thrown instanceof Error ? thrown.message : 'Invalid JSON') ); ``` ## How this differs from Rust Rust uses a `match` expression. In TypeScript, call [`Result.match()`](../api/interfaces/ResultMethods.md#match) or [`Option.match()`](../api/interfaces/OptionMethods.md#match) with a handler for each variant. The constructors and panic methods use Rust's names. See the [API reference](../api/index.md) for this library's behavior and the [Rust documentation](https://doc.rust-lang.org/std/) for Rust's types. ## Next steps - [Async support](./async.md) explains how to chain and await async operations. - [API reference](../api/index.md) lists method signatures and behavior. # Async results and options [`AsyncResult`](../api/interfaces/AsyncResult.md) and [`AsyncOption`](../api/interfaces/AsyncOption.md) let you chain operations before awaiting a result or option: - Await an [`AsyncResult`](../api/interfaces/AsyncResult.md) to get a [`Result`](../api/type-aliases/Result.md). - Await an [`AsyncOption`](../api/interfaces/AsyncOption.md) to get an [`Option`](../api/type-aliases/Option.md). ## Getting an async value ```typescript import { Ok } from 'results-ts'; const asyncResult = Ok(1).mapAsync(async (n) => n + 1); // ^? AsyncResult const result = await asyncResult; // Ok(2) ``` `mapAsync` returns an async wrapper. Its chainable methods also return async wrappers. ## Chaining Chain methods on [`AsyncResult`](../api/interfaces/AsyncResult.md) and [`AsyncOption`](../api/interfaces/AsyncOption.md) as you would on their synchronous types: ```typescript import { Ok, Err } from 'results-ts'; const loadUser = async (id: number) => { if (id === 13) return Err({ code: 'NOT_FOUND', id } as const); return Ok({ id, name: 'Ada' }); }; const name = await Ok(1) .andThenAsync(loadUser) .map((user) => user.name) .unwrapOr('anonymous'); ``` Methods such as [`AsyncResult.unwrapOr()`](../api/interfaces/AsyncResult.md#unwrapor) return a `Promise` of the contained value or fallback. The example awaits that promise to get a string. Use [`AsyncResult.match()`](../api/interfaces/AsyncResult.md#match) to handle each variant with a function. Callbacks in ordinary chains do not convert thrown errors or rejected promises to `Err`. Those failures propagate. Return `Err` for recoverable failures, or see [Exception adapters](./error-handling.md#exception-adapters) for an unavoidable throwing boundary. ## Panics become rejections [`Result.unwrap()`](../api/interfaces/ResultMethods.md#unwrap) and [`Result.expect()`](../api/interfaces/ResultMethods.md#expect) throw on `Err`. [`Result.unwrapErr()`](../api/interfaces/ResultMethods.md#unwraperr) and [`Result.expectErr()`](../api/interfaces/ResultMethods.md#expecterr) throw on `Ok`. The same methods on [`AsyncResult`](../api/interfaces/AsyncResult.md) reject with `PanicError`. For recoverable failures, use [`AsyncResult.unwrapOr()`](../api/interfaces/AsyncResult.md#unwrapor), [`AsyncResult.unwrapOrElse()`](../api/interfaces/AsyncResult.md#unwraporelse), or [`AsyncResult.match()`](../api/interfaces/AsyncResult.md#match). ```typescript import { Ok, Err } from 'results-ts'; // Resolves to 42. const value = await Ok(21) .mapAsync(async (n) => n * 2) .unwrap(); // 42 // Rejects with PanicError. await Err('boom') .mapAsync(async (n) => n) .unwrap(); // PanicError: called `Result.unwrap()` on an `Err` value ``` The same applies to [`AsyncOption`](../api/interfaces/AsyncOption.md)'s panic methods. ## Next steps - [`AsyncResult` API](../api/interfaces/AsyncResult.md) lists the async result methods. - [`AsyncOption` API](../api/interfaces/AsyncOption.md) lists the async option methods. - [Error handling](./error-handling.md) covers panics and functions that throw. **results-ts** *** # results-ts ## Interfaces - [AsyncOption](interfaces/AsyncOption.md) - [AsyncResult](interfaces/AsyncResult.md) - [OptionMethods](interfaces/OptionMethods.md) - [ResultMethods](interfaces/ResultMethods.md) ## Type Aliases - [ErrResult](type-aliases/ErrResult.md) - [NoneOption](type-aliases/NoneOption.md) - [OkResult](type-aliases/OkResult.md) - [Option](type-aliases/Option.md) - [Result](type-aliases/Result.md) - [SomeOption](type-aliases/SomeOption.md) ## Functions - [catchUnwind](functions/catchUnwind.md) - [catchUnwindAsync](functions/catchUnwindAsync.md) - [Err](functions/Err.md) - [None](functions/None.md) - [Ok](functions/Ok.md) - [Some](functions/Some.md) [**results-ts**](../index.md) *** [results-ts](../index.md) / AsyncOption # Interface: AsyncOption\ Defined in: [async-option.ts:19](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L19) An awaitable wrapper around `Option` with chainable methods. `and`, `or`, `xor`, and `zip` accept sync or promise-like operands. Async operands resolve concurrently with the receiver. Either rejection propagates. `AsyncOption` omits `insert`, `getOrInsert`, `getOrInsertWith`, `getOrInsertWithAsync`, `take`, `takeIf`, and `replace`. Await the wrapper to get an `Option`, then call its mutation methods. Methods that throw on `Option` reject on `AsyncOption`. For example, `unwrap` rejects on `None`, and `flatten` rejects a non-nested value. ## Extends - `PromiseLike`\<[`Option`](../type-aliases/Option.md)\<`T`\>\> ## Type Parameters ### T `T` ## Methods ### and() > **and**\<`U`\>(`optb`): `AsyncOption`\<`U`\> Defined in: [async-option.ts:139](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L139) Returns `None` if the option is `None`, otherwise returns `optb`. #### Type Parameters ##### U `U` #### Parameters ##### optb [`Option`](../type-aliases/Option.md)\<`U`\> \| `PromiseLike`\<[`Option`](../type-aliases/Option.md)\<`U`\>\> #### Returns `AsyncOption`\<`U`\> *** ### andThen() > **andThen**\<`U`\>(`f`): `AsyncOption`\<`U`\> Defined in: [async-option.ts:144](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L144) Returns `None` if the option is `None`, otherwise calls `f` with the wrapped value and returns the result. #### Type Parameters ##### U `U` #### Parameters ##### f (`val`) => [`Option`](../type-aliases/Option.md)\<`U`\> #### Returns `AsyncOption`\<`U`\> *** ### andThenAsync() > **andThenAsync**\<`U`\>(`f`): `AsyncOption`\<`U`\> Defined in: [async-option.ts:149](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L149) Async version of `andThen`. Returns `None` if the option is `None`, otherwise calls async `f` with the wrapped value and returns the result. #### Type Parameters ##### U `U` #### Parameters ##### f (`val`) => `PromiseLike`\<[`Option`](../type-aliases/Option.md)\<`U`\>\> #### Returns `AsyncOption`\<`U`\> *** ### expect() > **expect**(`msg`): `Promise`\<`T`\> Defined in: [async-option.ts:51](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L51) Returns the contained `Some` value. #### Parameters ##### msg `string` #### Returns `Promise`\<`T`\> #### Throws Rejects with `PanicError` if the value is a `None` with a custom panic message provided by `msg`. *** ### filter() > **filter**(`predicate`): `AsyncOption`\<`T`\> Defined in: [async-option.ts:156](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L156) Returns `None` if the option is `None`, otherwise calls `predicate` with the wrapped value and returns: - `Some(t)` if `predicate` returns `true` (where `t` is the wrapped value), and - `None` if `predicate` returns `false`. #### Parameters ##### predicate (`val`) => `boolean` #### Returns `AsyncOption`\<`T`\> *** ### filterAsync() > **filterAsync**(`predicate`): `AsyncOption`\<`T`\> Defined in: [async-option.ts:163](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L163) Async version of `filter`. Returns `None` if the option is `None`, otherwise calls async `predicate` with the wrapped value and returns: - `Some(t)` if `predicate` resolves to `true` (where `t` is the wrapped value), and - `None` if `predicate` resolves to `false`. #### Parameters ##### predicate (`val`) => `PromiseLike`\<`boolean`\> #### Returns `AsyncOption`\<`T`\> *** ### flatten() > **flatten**\<`U`\>(`this`): `AsyncOption`\<`U`\> Defined in: [async-option.ts:191](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L191) Converts from `AsyncOption>` to `AsyncOption`. **Async note:** If the inner value is not an `Option`, this produces a rejected `Promise` with `FlattenError` rather than a synchronous throw. #### Type Parameters ##### U `U` #### Parameters ##### this `AsyncOption`\<[`Option`](../type-aliases/Option.md)\<`U`\>\> #### Returns `AsyncOption`\<`U`\> *** ### inspect() > **inspect**(`f`): `AsyncOption`\<`T`\> Defined in: [async-option.ts:90](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L90) Calls `f` with the `Some` value and returns the original option. Returns the original option. #### Parameters ##### f (`val`) => `void` #### Returns `AsyncOption`\<`T`\> *** ### inspectAsync() > **inspectAsync**(`f`): `AsyncOption`\<`T`\> Defined in: [async-option.ts:95](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L95) Awaits `f` with the `Some` value and returns the original option. #### Parameters ##### f (`val`) => `PromiseLike`\<`void`\> #### Returns `AsyncOption`\<`T`\> *** ### isNone() > **isNone**(): `Promise`\<`boolean`\> Defined in: [async-option.ts:39](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L39) Returns a `Promise` that resolves to `true` if the option is a `None` value. #### Returns `Promise`\<`boolean`\> *** ### isNoneOr() > **isNoneOr**(`f`): `Promise`\<`boolean`\> Defined in: [async-option.ts:44](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L44) Returns a `Promise` that resolves to `true` if the option is a `None` or its value matches the predicate. #### Parameters ##### f (`val`) => `boolean` #### Returns `Promise`\<`boolean`\> *** ### isSome() > **isSome**(): `Promise`\<`boolean`\> Defined in: [async-option.ts:29](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L29) Returns a `Promise` that resolves to `true` if the option is a `Some` value. #### Returns `Promise`\<`boolean`\> *** ### isSomeAnd() > **isSomeAnd**(`f`): `Promise`\<`boolean`\> Defined in: [async-option.ts:34](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L34) Returns a `Promise` that resolves to `true` if the option is a `Some` and its value matches the predicate. #### Parameters ##### f (`val`) => `boolean` #### Returns `Promise`\<`boolean`\> *** ### iter() > **iter**(): `AsyncIterableIterator`\<`Awaited`\<`T`\>, `undefined`, `unknown`\> Defined in: [async-option.ts:134](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L134) Returns an async iterator that yields the `Some` value once, or nothing for `None`. Promise-like payloads are awaited. Source and payload rejections propagate. #### Returns `AsyncIterableIterator`\<`Awaited`\<`T`\>, `undefined`, `unknown`\> *** ### map() > **map**\<`U`\>(`f`): `AsyncOption`\<`U`\> Defined in: [async-option.ts:78](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L78) Maps an `AsyncOption` to `AsyncOption` by applying a function to a contained value. #### Type Parameters ##### U `U` #### Parameters ##### f (`val`) => `U` #### Returns `AsyncOption`\<`U`\> *** ### mapAsync() > **mapAsync**\<`U`\>(`f`): `AsyncOption`\<`U`\> Defined in: [async-option.ts:83](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L83) Async version of `map`. Maps an `AsyncOption` to `AsyncOption` by applying an async function to a contained value. #### Type Parameters ##### U `U` #### Parameters ##### f (`val`) => `PromiseLike`\<`U`\> #### Returns `AsyncOption`\<`U`\> *** ### mapOr() > **mapOr**\<`U`\>(`defaultVal`, `f`): `Promise`\<`U`\> Defined in: [async-option.ts:100](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L100) Returns the fallback on `None`, or calls `f` with the `Some` value. #### Type Parameters ##### U `U` #### Parameters ##### defaultVal `U` ##### f (`val`) => `U` #### Returns `Promise`\<`U`\> *** ### mapOrElse() > **mapOrElse**\<`U`\>(`defaultF`, `f`): `Promise`\<`U`\> Defined in: [async-option.ts:105](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L105) Calls `defaultF` on `None`, or calls `f` with the `Some` value. #### Type Parameters ##### U `U` #### Parameters ##### defaultF () => `U` ##### f (`val`) => `U` #### Returns `Promise`\<`U`\> *** ### mapOrElseAsync() > **mapOrElseAsync**\<`U`\>(`defaultF`, `f`): `Promise`\<`U`\> Defined in: [async-option.ts:110](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L110) Awaits `defaultF` on `None`, or awaits `f` with the `Some` value. #### Type Parameters ##### U `U` #### Parameters ##### defaultF () => `PromiseLike`\<`U`\> ##### f (`val`) => `PromiseLike`\<`U`\> #### Returns `Promise`\<`U`\> *** ### match() > **match**\<`U`\>(`handlers`): `Promise`\<`U`\> Defined in: [async-option.ts:219](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L219) Matches the `Option` with two functions, one for each variant. #### Type Parameters ##### U `U` #### Parameters ##### handlers ###### None () => `U` ###### Some (`val`) => `U` #### Returns `Promise`\<`U`\> *** ### okOr() > **okOr**\<`E`\>(`err`): [`AsyncResult`](AsyncResult.md)\<`T`, `E`\> Defined in: [async-option.ts:118](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L118) Transforms the `AsyncOption` into an `AsyncResult`, mapping `Some(v)` to `Ok(v)` and `None` to `Err(err)`. #### Type Parameters ##### E `E` #### Parameters ##### err `E` #### Returns [`AsyncResult`](AsyncResult.md)\<`T`, `E`\> *** ### okOrElse() > **okOrElse**\<`E`\>(`errF`): [`AsyncResult`](AsyncResult.md)\<`T`, `E`\> Defined in: [async-option.ts:123](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L123) Transforms the `AsyncOption` into an `AsyncResult`, mapping `Some(v)` to `Ok(v)` and `None` to `Err(err())`. #### Type Parameters ##### E `E` #### Parameters ##### errF () => `E` #### Returns [`AsyncResult`](AsyncResult.md)\<`T`, `E`\> *** ### okOrElseAsync() > **okOrElseAsync**\<`E`\>(`errF`): [`AsyncResult`](AsyncResult.md)\<`T`, `E`\> Defined in: [async-option.ts:128](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L128) Async version of `okOrElse`. Transforms the `AsyncOption` into an `AsyncResult`, mapping `Some(v)` to `Ok(v)` and `None` to `Err(await errF())`. #### Type Parameters ##### E `E` #### Parameters ##### errF () => `PromiseLike`\<`E`\> #### Returns [`AsyncResult`](AsyncResult.md)\<`T`, `E`\> *** ### or() > **or**\<`T2`\>(`optb`): `AsyncOption`\<`T` \| `T2`\> Defined in: [async-option.ts:168](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L168) Returns the option if it contains a value, otherwise returns `optb`. #### Type Parameters ##### T2 `T2` #### Parameters ##### optb [`Option`](../type-aliases/Option.md)\<`T2`\> \| `PromiseLike`\<[`Option`](../type-aliases/Option.md)\<`T2`\>\> #### Returns `AsyncOption`\<`T` \| `T2`\> *** ### orElse() > **orElse**\<`T2`\>(`f`): `AsyncOption`\<`T` \| `T2`\> Defined in: [async-option.ts:173](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L173) Returns the option if it contains a value, otherwise calls `f` and returns the result. #### Type Parameters ##### T2 `T2` #### Parameters ##### f () => [`Option`](../type-aliases/Option.md)\<`T2`\> #### Returns `AsyncOption`\<`T` \| `T2`\> *** ### orElseAsync() > **orElseAsync**\<`T2`\>(`f`): `AsyncOption`\<`T` \| `T2`\> Defined in: [async-option.ts:178](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L178) Async version of `orElse`. Returns the option if it contains a value, otherwise calls async `f` and returns the result. #### Type Parameters ##### T2 `T2` #### Parameters ##### f () => `PromiseLike`\<[`Option`](../type-aliases/Option.md)\<`T2`\>\> #### Returns `AsyncOption`\<`T` \| `T2`\> *** ### toString() > **toString**(): `Promise`\<`string`\> Defined in: [async-option.ts:24](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L24) Resolves to the contained option's string representation. Call with `await option.toString()`; implicit string conversion does not await it. #### Returns `Promise`\<`string`\> *** ### transpose() > **transpose**\<`T`, `E`\>(`this`): [`AsyncResult`](AsyncResult.md)\<[`Option`](../type-aliases/Option.md)\<`T`\>, `E`\> Defined in: [async-option.ts:199](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L199) Transposes an `AsyncOption` of a `Result` into an `AsyncResult` of an `Option`. **Async note:** If the inner value is not a `Result`, this produces a rejected `Promise` with `TransposeError` rather than a synchronous throw. #### Type Parameters ##### T `T` ##### E `E` #### Parameters ##### this `AsyncOption`\<[`Result`](../type-aliases/Result.md)\<`T`, `E`\>\> #### Returns [`AsyncResult`](AsyncResult.md)\<[`Option`](../type-aliases/Option.md)\<`T`\>, `E`\> *** ### unwrap() > **unwrap**(): `Promise`\<`T`\> Defined in: [async-option.ts:58](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L58) Returns the contained `Some` value. #### Returns `Promise`\<`T`\> #### Throws Rejects with `PanicError` if the self value equals `None`. *** ### unwrapOr() > **unwrapOr**(`defaultVal`): `Promise`\<`T`\> Defined in: [async-option.ts:63](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L63) Returns the contained `Some` value or a provided default. #### Parameters ##### defaultVal `T` #### Returns `Promise`\<`T`\> *** ### unwrapOrElse() > **unwrapOrElse**(`f`): `Promise`\<`T`\> Defined in: [async-option.ts:68](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L68) Returns the contained `Some` value, or calls `f` on `None`. #### Parameters ##### f () => `T` #### Returns `Promise`\<`T`\> *** ### unwrapOrElseAsync() > **unwrapOrElseAsync**(`f`): `Promise`\<`T`\> Defined in: [async-option.ts:73](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L73) Returns the `Some` value, or awaits `f` on `None`. #### Parameters ##### f () => `PromiseLike`\<`T`\> #### Returns `Promise`\<`T`\> *** ### unzip() > **unzip**\<`T`, `U`\>(`this`): \[`AsyncOption`\<`T`\>, `AsyncOption`\<`U`\>\] Defined in: [async-option.ts:214](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L214) Unzips an `AsyncOption` containing a tuple of two values. Returns two async options. They resolve to `Some(a)` and `Some(b)` for `Some([a, b])`, or both resolve to `None` for `None`. #### Type Parameters ##### T `T` ##### U `U` #### Parameters ##### this `AsyncOption`\<\[`T`, `U`\]\> #### Returns \[`AsyncOption`\<`T`\>, `AsyncOption`\<`U`\>\] *** ### xor() > **xor**\<`T2`\>(`optb`): `AsyncOption`\<`T` \| `T2`\> Defined in: [async-option.ts:183](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L183) Returns `Some` if exactly one of `this`, `optb` is `Some`, otherwise returns `None`. #### Type Parameters ##### T2 `T2` #### Parameters ##### optb [`Option`](../type-aliases/Option.md)\<`T2`\> \| `PromiseLike`\<[`Option`](../type-aliases/Option.md)\<`T2`\>\> #### Returns `AsyncOption`\<`T` \| `T2`\> *** ### zip() > **zip**\<`U`\>(`other`): `AsyncOption`\<\[`T`, `U`\]\> Defined in: [async-option.ts:206](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-option.ts#L206) Combines the resolved option with another option into a tuple of their values. Resolves to `Some([a, b])` if both options are `Some`, otherwise resolves to `None`. #### Type Parameters ##### U `U` #### Parameters ##### other [`Option`](../type-aliases/Option.md)\<`U`\> \| `PromiseLike`\<[`Option`](../type-aliases/Option.md)\<`U`\>\> #### Returns `AsyncOption`\<\[`T`, `U`\]\> [**results-ts**](../index.md) *** [results-ts](../index.md) / AsyncResult # Interface: AsyncResult\ Defined in: [async-result.ts:16](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L16) An awaitable wrapper around `Result` with chainable methods. `and` and `or` accept sync or promise-like operands. Async operands resolve concurrently with the receiver. Either rejection propagates. Methods that throw on `Result` reject on `AsyncResult`. For example, `unwrap` rejects on `Err`, and `flatten` rejects a non-nested value. ## Extends - `PromiseLike`\<[`Result`](../type-aliases/Result.md)\<`T`, `E`\>\> ## Type Parameters ### T `T` ### E `E` ## Methods ### and() > **and**\<`U`, `E2`\>(`res`): `AsyncResult`\<`U`, `E` \| `E2`\> Defined in: [async-result.ts:160](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L160) Returns `res` if the result is `Ok`, otherwise returns the `Err` value of `self`. JavaScript evaluates the operand before the call. Use `andThen` to compute it only on `Ok`. #### Type Parameters ##### U `U` ##### E2 `E2` #### Parameters ##### res [`Result`](../type-aliases/Result.md)\<`U`, `E2`\> \| `PromiseLike`\<[`Result`](../type-aliases/Result.md)\<`U`, `E2`\>\> #### Returns `AsyncResult`\<`U`, `E` \| `E2`\> *** ### andThen() > **andThen**\<`U`, `F`\>(`f`): `AsyncResult`\<`U`, `E` \| `F`\> Defined in: [async-result.ts:167](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L167) Calls `f` if the result is `Ok`, otherwise returns the `Err` value of `self`. #### Type Parameters ##### U `U` ##### F `F` #### Parameters ##### f (`val`) => [`Result`](../type-aliases/Result.md)\<`U`, `F`\> #### Returns `AsyncResult`\<`U`, `E` \| `F`\> *** ### andThenAsync() > **andThenAsync**\<`U`, `F`\>(`f`): `AsyncResult`\<`U`, `E` \| `F`\> Defined in: [async-result.ts:172](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L172) Async version of `andThen`. Calls an async `f` if the result is `Ok`, otherwise returns the `Err` value of `self`. #### Type Parameters ##### U `U` ##### F `F` #### Parameters ##### f (`val`) => `PromiseLike`\<[`Result`](../type-aliases/Result.md)\<`U`, `F`\>\> #### Returns `AsyncResult`\<`U`, `E` \| `F`\> *** ### err() > **err**(): [`AsyncOption`](AsyncOption.md)\<`E`\> Defined in: [async-result.ts:55](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L55) Converts from `AsyncResult` to `AsyncOption`. Returns `Some` for `Err` and `None` for `Ok`. #### Returns [`AsyncOption`](AsyncOption.md)\<`E`\> *** ### expect() > **expect**(`msg`): `Promise`\<`T`\> Defined in: [async-result.ts:132](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L132) Returns the contained `Ok` value. #### Parameters ##### msg `string` #### Returns `Promise`\<`T`\> #### Throws Rejects with `PanicError` if the value is an `Err`, with a panic message including the passed message, and the content of the `Err`. *** ### expectErr() > **expectErr**(`msg`): `Promise`\<`E`\> Defined in: [async-result.ts:146](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L146) Returns the contained `Err` value. #### Parameters ##### msg `string` #### Returns `Promise`\<`E`\> #### Throws Rejects with `PanicError` if the value is an `Ok`, with a panic message including the passed message, and the content of the `Ok`. *** ### flatten() > **flatten**\<`U`, `F`\>(`this`): `AsyncResult`\<`U`, `E` \| `F`\> Defined in: [async-result.ts:220](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L220) Converts from `AsyncResult, E>` to `AsyncResult`. **Async note:** If the inner value is not a `Result`, this produces a rejected `Promise` with `FlattenError` rather than a synchronous throw. #### Type Parameters ##### U `U` ##### F `F` #### Parameters ##### this `AsyncResult`\<[`Result`](../type-aliases/Result.md)\<`U`, `F`\>, `E`\> #### Returns `AsyncResult`\<`U`, `E` \| `F`\> *** ### inspect() > **inspect**(`f`): `AsyncResult`\<`T`, `E`\> Defined in: [async-result.ts:102](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L102) Calls a function with a reference to the contained value if `Ok`. Returns the original result. #### Parameters ##### f (`val`) => `void` #### Returns `AsyncResult`\<`T`, `E`\> *** ### inspectAsync() > **inspectAsync**(`f`): `AsyncResult`\<`T`, `E`\> Defined in: [async-result.ts:107](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L107) Async version of `inspect`. Calls an async function with a reference to the contained value if `Ok`, then returns the original result. #### Parameters ##### f (`val`) => `PromiseLike`\<`void`\> #### Returns `AsyncResult`\<`T`, `E`\> *** ### inspectErr() > **inspectErr**(`f`): `AsyncResult`\<`T`, `E`\> Defined in: [async-result.ts:114](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L114) Calls a function with a reference to the contained value if `Err`. Returns the original result. #### Parameters ##### f (`err`) => `void` #### Returns `AsyncResult`\<`T`, `E`\> *** ### inspectErrAsync() > **inspectErrAsync**(`f`): `AsyncResult`\<`T`, `E`\> Defined in: [async-result.ts:119](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L119) Async version of `inspectErr`. Calls an async function with a reference to the contained value if `Err`, then returns the original result. #### Parameters ##### f (`err`) => `PromiseLike`\<`void`\> #### Returns `AsyncResult`\<`T`, `E`\> *** ### isErr() > **isErr**(): `Promise`\<`boolean`\> Defined in: [async-result.ts:36](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L36) Returns a `Promise` that resolves to `true` if the result is `Err`. #### Returns `Promise`\<`boolean`\> *** ### isErrAnd() > **isErrAnd**(`f`): `Promise`\<`boolean`\> Defined in: [async-result.ts:41](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L41) Returns a `Promise` that resolves to `true` if the result is `Err` and the error inside matches a predicate. #### Parameters ##### f (`err`) => `boolean` #### Returns `Promise`\<`boolean`\> *** ### isOk() > **isOk**(): `Promise`\<`boolean`\> Defined in: [async-result.ts:26](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L26) Returns a `Promise` that resolves to `true` if the result is `Ok`. #### Returns `Promise`\<`boolean`\> *** ### isOkAnd() > **isOkAnd**(`f`): `Promise`\<`boolean`\> Defined in: [async-result.ts:31](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L31) Returns a `Promise` that resolves to `true` if the result is `Ok` and its value matches the predicate. #### Parameters ##### f (`val`) => `boolean` #### Returns `Promise`\<`boolean`\> *** ### iter() > **iter**(): `AsyncIterableIterator`\<`Awaited`\<`T`\>, `undefined`, `unknown`\> Defined in: [async-result.ts:125](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L125) Returns an async iterator that yields the `Ok` value once, or nothing for `Err`. Promise-like payloads are awaited. Source and payload rejections propagate. #### Returns `AsyncIterableIterator`\<`Awaited`\<`T`\>, `undefined`, `unknown`\> *** ### map() > **map**\<`U`\>(`f`): `AsyncResult`\<`U`, `E`\> Defined in: [async-result.ts:60](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L60) Maps an `AsyncResult` to `AsyncResult` by applying a function to a contained `Ok` value, leaving an `Err` value untouched. #### Type Parameters ##### U `U` #### Parameters ##### f (`val`) => `U` #### Returns `AsyncResult`\<`U`, `E`\> *** ### mapAsync() > **mapAsync**\<`U`\>(`f`): `AsyncResult`\<`U`, `E`\> Defined in: [async-result.ts:65](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L65) Async version of `map`. Maps an `AsyncResult` to `AsyncResult` by applying an async function to a contained `Ok` value, leaving an `Err` value untouched. #### Type Parameters ##### U `U` #### Parameters ##### f (`val`) => `PromiseLike`\<`U`\> #### Returns `AsyncResult`\<`U`, `E`\> *** ### mapErr() > **mapErr**\<`F`\>(`f`): `AsyncResult`\<`T`, `F`\> Defined in: [async-result.ts:90](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L90) Maps an `AsyncResult` to `AsyncResult` by applying a function to a contained `Err` value, leaving an `Ok` value untouched. #### Type Parameters ##### F `F` #### Parameters ##### f (`err`) => `F` #### Returns `AsyncResult`\<`T`, `F`\> *** ### mapErrAsync() > **mapErrAsync**\<`F`\>(`f`): `AsyncResult`\<`T`, `F`\> Defined in: [async-result.ts:95](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L95) Async version of `mapErr`. Maps an `AsyncResult` to `AsyncResult` by applying an async function to a contained `Err` value, leaving an `Ok` value untouched. #### Type Parameters ##### F `F` #### Parameters ##### f (`err`) => `PromiseLike`\<`F`\> #### Returns `AsyncResult`\<`T`, `F`\> *** ### mapOr() > **mapOr**\<`U`\>(`fallback`, `f`): `Promise`\<`U`\> Defined in: [async-result.ts:72](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L72) Returns the fallback on `Err`, or calls `f` with the `Ok` value. JavaScript evaluates the fallback before the call. Use `mapOrElse` to compute it only on `Err`. #### Type Parameters ##### U `U` #### Parameters ##### fallback `U` ##### f (`val`) => `U` #### Returns `Promise`\<`U`\> *** ### mapOrElse() > **mapOrElse**\<`U`\>(`fallbackFn`, `f`): `Promise`\<`U`\> Defined in: [async-result.ts:77](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L77) Maps an `AsyncResult` to `U` by applying fallback function `fallbackFn` to a contained `Err` value, or function `f` to a contained `Ok` value. #### Type Parameters ##### U `U` #### Parameters ##### fallbackFn (`err`) => `U` ##### f (`val`) => `U` #### Returns `Promise`\<`U`\> *** ### mapOrElseAsync() > **mapOrElseAsync**\<`U`\>(`fallbackFn`, `f`): `Promise`\<`U`\> Defined in: [async-result.ts:82](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L82) Async version of `mapOrElse`. Maps an `AsyncResult` to `Promise` by applying async fallback function `fallbackFn` to a contained `Err` value, or async function `f` to a contained `Ok` value. #### Type Parameters ##### U `U` #### Parameters ##### fallbackFn (`err`) => `PromiseLike`\<`U`\> ##### f (`val`) => `PromiseLike`\<`U`\> #### Returns `Promise`\<`U`\> *** ### match() > **match**\<`U`\>(`handlers`): `Promise`\<`U`\> Defined in: [async-result.ts:233](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L233) Matches the `Result` with two functions, one for each variant. #### Type Parameters ##### U `U` #### Parameters ##### handlers ###### Err (`err`) => `U` ###### Ok (`val`) => `U` #### Returns `Promise`\<`U`\> *** ### ok() > **ok**(): [`AsyncOption`](AsyncOption.md)\<`T`\> Defined in: [async-result.ts:48](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L48) Converts from `AsyncResult` to `AsyncOption`. Returns `Some` for `Ok` and `None` for `Err`. #### Returns [`AsyncOption`](AsyncOption.md)\<`T`\> *** ### or() > **or**\<`T2`, `F`\>(`res`): `AsyncResult`\<`T` \| `T2`, `F`\> Defined in: [async-result.ts:181](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L181) Returns `res` if the result is `Err`, otherwise returns the `Ok` value of `self`. JavaScript evaluates the operand before the call. Use `orElse` to compute it only on `Err`. #### Type Parameters ##### T2 `T2` ##### F `F` #### Parameters ##### res [`Result`](../type-aliases/Result.md)\<`T2`, `F`\> \| `PromiseLike`\<[`Result`](../type-aliases/Result.md)\<`T2`, `F`\>\> #### Returns `AsyncResult`\<`T` \| `T2`, `F`\> *** ### orElse() > **orElse**\<`T2`, `F`\>(`f`): `AsyncResult`\<`T` \| `T2`, `F`\> Defined in: [async-result.ts:188](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L188) Calls `f` if the result is `Err`, otherwise returns the `Ok` value of `self`. #### Type Parameters ##### T2 `T2` ##### F `F` #### Parameters ##### f (`err`) => [`Result`](../type-aliases/Result.md)\<`T2`, `F`\> #### Returns `AsyncResult`\<`T` \| `T2`, `F`\> *** ### orElseAsync() > **orElseAsync**\<`T2`, `F`\>(`f`): `AsyncResult`\<`T` \| `T2`, `F`\> Defined in: [async-result.ts:193](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L193) Async version of `orElse`. Calls an async `f` if the result is `Err`, otherwise returns the `Ok` value of `self`. #### Type Parameters ##### T2 `T2` ##### F `F` #### Parameters ##### f (`err`) => `PromiseLike`\<[`Result`](../type-aliases/Result.md)\<`T2`, `F`\>\> #### Returns `AsyncResult`\<`T` \| `T2`, `F`\> *** ### toString() > **toString**(): `Promise`\<`string`\> Defined in: [async-result.ts:21](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L21) Resolves to the contained result's string representation. Call with `await result.toString()`; implicit string conversion does not await it. #### Returns `Promise`\<`string`\> *** ### transpose() > **transpose**\<`T`, `E`\>(`this`): [`AsyncOption`](AsyncOption.md)\<[`Result`](../type-aliases/Result.md)\<`T`, `E`\>\> Defined in: [async-result.ts:228](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L228) Transposes an `AsyncResult` of an `Option` into an `AsyncOption` of a `Result`. **Async note:** If the inner value is not an `Option`, this produces a rejected `Promise` with `TransposeError` rather than a synchronous throw. #### Type Parameters ##### T `T` ##### E `E` #### Parameters ##### this `AsyncResult`\<[`Option`](../type-aliases/Option.md)\<`T`\>, `E`\> #### Returns [`AsyncOption`](AsyncOption.md)\<[`Result`](../type-aliases/Result.md)\<`T`, `E`\>\> *** ### unwrap() > **unwrap**(): `Promise`\<`T`\> Defined in: [async-result.ts:139](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L139) Returns the contained `Ok` value. #### Returns `Promise`\<`T`\> #### Throws Rejects with `PanicError` if the value is an `Err`, with a panic message provided by the `Err`'s value. *** ### unwrapErr() > **unwrapErr**(): `Promise`\<`E`\> Defined in: [async-result.ts:153](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L153) Returns the contained `Err` value. #### Returns `Promise`\<`E`\> #### Throws Rejects with `PanicError` if the value is an `Ok`, with a custom panic message provided by the `Ok`'s value. *** ### unwrapOr() > **unwrapOr**\<`T2`\>(`fallback`): `Promise`\<`T` \| `T2`\> Defined in: [async-result.ts:202](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L202) Returns the contained `Ok` value or a provided default. JavaScript evaluates the fallback before the call. Use `unwrapOrElse` to compute it only on `Err`. #### Type Parameters ##### T2 `T2` #### Parameters ##### fallback `T2` #### Returns `Promise`\<`T` \| `T2`\> *** ### unwrapOrElse() > **unwrapOrElse**\<`T2`\>(`f`): `Promise`\<`T` \| `T2`\> Defined in: [async-result.ts:207](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L207) Returns the contained `Ok` value, or calls `f` with the error. #### Type Parameters ##### T2 `T2` #### Parameters ##### f (`err`) => `T2` #### Returns `Promise`\<`T` \| `T2`\> *** ### unwrapOrElseAsync() > **unwrapOrElseAsync**\<`T2`\>(`f`): `Promise`\<`T` \| `T2`\> Defined in: [async-result.ts:212](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L212) Returns the `Ok` value, or awaits `f` with the error. #### Type Parameters ##### T2 `T2` #### Parameters ##### f (`err`) => `PromiseLike`\<`T2`\> #### Returns `Promise`\<`T` \| `T2`\> [**results-ts**](../index.md) *** [results-ts](../index.md) / OptionMethods # Interface: OptionMethods\ Defined in: [option.ts:43](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L43) ## Type Parameters ### T `T` ## Methods ### and() #### Call Signature > **and**\<`U`\>(`optb`): [`Option`](../type-aliases/Option.md)\<`U`\> Defined in: [option.ts:157](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L157) Returns `None` if the option is `None`, otherwise returns `optb`. ##### Type Parameters ###### U `U` ##### Parameters ###### optb [`Option`](../type-aliases/Option.md)\<`U`\> ##### Returns [`Option`](../type-aliases/Option.md)\<`U`\> #### Call Signature > **and**\<`U`\>(`optb`): [`AsyncOption`](AsyncOption.md)\<`U`\> Defined in: [option.ts:158](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L158) ##### Type Parameters ###### U `U` ##### Parameters ###### optb `PromiseLike`\<[`Option`](../type-aliases/Option.md)\<`U`\>\> ##### Returns [`AsyncOption`](AsyncOption.md)\<`U`\> #### Call Signature > **and**\<`U`\>(`optb`): [`Option`](../type-aliases/Option.md)\<`U`\> \| [`AsyncOption`](AsyncOption.md)\<`U`\> Defined in: [option.ts:159](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L159) ##### Type Parameters ###### U `U` ##### Parameters ###### optb [`Option`](../type-aliases/Option.md)\<`U`\> \| `PromiseLike`\<[`Option`](../type-aliases/Option.md)\<`U`\>\> ##### Returns [`Option`](../type-aliases/Option.md)\<`U`\> \| [`AsyncOption`](AsyncOption.md)\<`U`\> *** ### andThen() > **andThen**\<`U`\>(`f`): [`Option`](../type-aliases/Option.md)\<`U`\> Defined in: [option.ts:166](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L166) Returns `None` if the option is `None`, otherwise calls `f` with the wrapped value and returns the result. #### Type Parameters ##### U `U` #### Parameters ##### f (`val`) => [`Option`](../type-aliases/Option.md)\<`U`\> #### Returns [`Option`](../type-aliases/Option.md)\<`U`\> *** ### andThenAsync() > **andThenAsync**\<`U`\>(`f`): [`AsyncOption`](AsyncOption.md)\<`U`\> Defined in: [option.ts:171](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L171) Async version of `andThen`. Returns `None` if the option is `None`, otherwise calls async `f` with the wrapped value and returns the result. #### Type Parameters ##### U `U` #### Parameters ##### f (`val`) => `PromiseLike`\<[`Option`](../type-aliases/Option.md)\<`U`\>\> #### Returns [`AsyncOption`](AsyncOption.md)\<`U`\> *** ### expect() > **expect**(`msg`): `T` Defined in: [option.ts:72](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L72) Returns the contained `Some` value. #### Parameters ##### msg `string` #### Returns `T` #### Throws `PanicError` with `msg` on `None`. *** ### filter() > **filter**(`predicate`): [`Option`](../type-aliases/Option.md)\<`T`\> Defined in: [option.ts:178](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L178) Returns `None` if the option is `None`, otherwise calls `predicate` with the wrapped value and returns: - `Some(t)` if `predicate` returns `true` (where `t` is the wrapped value), and - `None` if `predicate` returns `false`. #### Parameters ##### predicate (`val`) => `boolean` #### Returns [`Option`](../type-aliases/Option.md)\<`T`\> *** ### filterAsync() > **filterAsync**(`predicate`): [`AsyncOption`](AsyncOption.md)\<`T`\> Defined in: [option.ts:185](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L185) Async version of `filter`. Returns `None` if the option is `None`, otherwise calls async `predicate` with the wrapped value and returns: - `Some(t)` if `predicate` resolves to `true` (where `t` is the wrapped value), and - `None` if `predicate` resolves to `false`. #### Parameters ##### predicate (`val`) => `PromiseLike`\<`boolean`\> #### Returns [`AsyncOption`](AsyncOption.md)\<`T`\> *** ### flatten() > **flatten**\<`U`\>(`this`): [`Option`](../type-aliases/Option.md)\<`U`\> Defined in: [option.ts:255](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L255) Converts from `Option>` to `Option`. #### Type Parameters ##### U `U` #### Parameters ##### this [`Option`](../type-aliases/Option.md)\<[`Option`](../type-aliases/Option.md)\<`U`\>\> #### Returns [`Option`](../type-aliases/Option.md)\<`U`\> #### Throws `FlattenError` if a `Some` value is not an `Option`. *** ### getOrInsert() > **getOrInsert**(`value`): `T` Defined in: [option.ts:223](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L223) Inserts `value` into the option if it is `None`, then returns a reference to the contained value. #### Parameters ##### value `T` #### Returns `T` *** ### getOrInsertWith() > **getOrInsertWith**(`f`): `T` Defined in: [option.ts:228](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L228) Inserts a value computed from `f` into the option if it is `None`, then returns a reference to the contained value. #### Parameters ##### f () => `T` #### Returns `T` *** ### getOrInsertWithAsync() > **getOrInsertWithAsync**(`f`): `Promise`\<`T`\> Defined in: [option.ts:233](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L233) Async version of `getOrInsertWith`. Inserts a value computed from async `f` into the option if it is `None`, then returns a reference to the contained value. #### Parameters ##### f () => `PromiseLike`\<`T`\> #### Returns `Promise`\<`T`\> *** ### insert() > **insert**(`value`): `T` Defined in: [option.ts:218](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L218) Inserts `value` into the option, then returns a reference to it. #### Parameters ##### value `T` #### Returns `T` *** ### inspect() > **inspect**(`f`): [`Option`](../type-aliases/Option.md)\<`T`\> Defined in: [option.ts:109](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L109) Calls `f` with the `Some` value and returns the original option. #### Parameters ##### f (`val`) => `void` #### Returns [`Option`](../type-aliases/Option.md)\<`T`\> *** ### inspectAsync() > **inspectAsync**(`f`): [`AsyncOption`](AsyncOption.md)\<`T`\> Defined in: [option.ts:114](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L114) Awaits `f` with the `Some` value and returns the original option. #### Parameters ##### f (`val`) => `PromiseLike`\<`void`\> #### Returns [`AsyncOption`](AsyncOption.md)\<`T`\> *** ### isNone() > **isNone**(): `this is NoneOption` Defined in: [option.ts:60](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L60) Returns `true` if the option is a `None` value. #### Returns `this is NoneOption` *** ### isNoneOr() > **isNoneOr**(`f`): `boolean` Defined in: [option.ts:65](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L65) Returns `true` if the option is a `None` or its value matches the predicate. #### Parameters ##### f (`val`) => `boolean` #### Returns `boolean` *** ### isSome() > **isSome**(): `this is SomeOption` Defined in: [option.ts:49](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L49) Returns `true` if the option is a `Some` value. #### Returns `this is SomeOption` *** ### isSomeAnd() #### Call Signature > **isSomeAnd**\<`U`\>(`f`): `this is SomeOption` Defined in: [option.ts:54](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L54) Returns `true` if the option is a `Some` and its value matches the predicate. ##### Type Parameters ###### U `U` ##### Parameters ###### f (`val`) => `val is U` ##### Returns `this is SomeOption` #### Call Signature > **isSomeAnd**(`f`): `this is SomeOption` Defined in: [option.ts:55](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L55) ##### Parameters ###### f (`val`) => `boolean` ##### Returns `this is SomeOption` *** ### iter() > **iter**(): `IterableIterator`\<`T`\> Defined in: [option.ts:152](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L152) Returns an iterator over the contained value, or an empty iterator if absent. #### Returns `IterableIterator`\<`T`\> *** ### map() > **map**\<`U`\>(`f`): [`Option`](../type-aliases/Option.md)\<`U`\> Defined in: [option.ts:99](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L99) Maps an `Option` to `Option` by applying a function to a contained value. #### Type Parameters ##### U `U` #### Parameters ##### f (`val`) => `U` #### Returns [`Option`](../type-aliases/Option.md)\<`U`\> *** ### mapAsync() > **mapAsync**\<`U`\>(`f`): [`AsyncOption`](AsyncOption.md)\<`U`\> Defined in: [option.ts:104](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L104) Async version of `map`. Maps an `Option` to `AsyncOption` by applying an async function to a contained value. #### Type Parameters ##### U `U` #### Parameters ##### f (`val`) => `PromiseLike`\<`U`\> #### Returns [`AsyncOption`](AsyncOption.md)\<`U`\> *** ### mapOr() > **mapOr**\<`U`\>(`defaultVal`, `f`): `U` Defined in: [option.ts:119](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L119) Returns the fallback on `None`, or calls `f` with the `Some` value. #### Type Parameters ##### U `U` #### Parameters ##### defaultVal `U` ##### f (`val`) => `U` #### Returns `U` *** ### mapOrElse() > **mapOrElse**\<`U`\>(`defaultF`, `f`): `U` Defined in: [option.ts:124](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L124) Calls `defaultF` on `None`, or calls `f` with the `Some` value. #### Type Parameters ##### U `U` #### Parameters ##### defaultF () => `U` ##### f (`val`) => `U` #### Returns `U` *** ### mapOrElseAsync() > **mapOrElseAsync**\<`U`\>(`defaultF`, `f`): `Promise`\<`U`\> Defined in: [option.ts:129](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L129) Awaits `defaultF` on `None`, or awaits `f` with the `Some` value. #### Type Parameters ##### U `U` #### Parameters ##### defaultF () => `PromiseLike`\<`U`\> ##### f (`val`) => `PromiseLike`\<`U`\> #### Returns `Promise`\<`U`\> *** ### match() > **match**\<`U`\>(`handlers`): `U` Defined in: [option.ts:288](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L288) Matches the `Option` with two functions, one for each variant. #### Type Parameters ##### U `U` #### Parameters ##### handlers ###### None () => `U` ###### Some (`val`) => `U` #### Returns `U` *** ### okOr() > **okOr**\<`E`\>(`err`): [`Result`](../type-aliases/Result.md)\<`T`, `E`\> Defined in: [option.ts:137](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L137) Transforms the `Option` into a `Result`, mapping `Some(v)` to `Ok(v)` and `None` to `Err(err)`. #### Type Parameters ##### E `E` #### Parameters ##### err `E` #### Returns [`Result`](../type-aliases/Result.md)\<`T`, `E`\> *** ### okOrElse() > **okOrElse**\<`E`\>(`errF`): [`Result`](../type-aliases/Result.md)\<`T`, `E`\> Defined in: [option.ts:142](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L142) Transforms the `Option` into a `Result`, mapping `Some(v)` to `Ok(v)` and `None` to `Err(err())`. #### Type Parameters ##### E `E` #### Parameters ##### errF () => `E` #### Returns [`Result`](../type-aliases/Result.md)\<`T`, `E`\> *** ### okOrElseAsync() > **okOrElseAsync**\<`E`\>(`errF`): [`AsyncResult`](AsyncResult.md)\<`T`, `E`\> Defined in: [option.ts:147](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L147) Async version of `okOrElse`. Converts the `Option` to an `AsyncResult`, mapping `Some(v)` to `Ok(v)` and `None` to `Err(await errF())`. #### Type Parameters ##### E `E` #### Parameters ##### errF () => `PromiseLike`\<`E`\> #### Returns [`AsyncResult`](AsyncResult.md)\<`T`, `E`\> *** ### or() #### Call Signature > **or**\<`T2`\>(`optb`): [`Option`](../type-aliases/Option.md)\<`T` \| `T2`\> Defined in: [option.ts:190](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L190) Returns the option if it contains a value, otherwise returns `optb`. ##### Type Parameters ###### T2 `T2` ##### Parameters ###### optb [`Option`](../type-aliases/Option.md)\<`T2`\> ##### Returns [`Option`](../type-aliases/Option.md)\<`T` \| `T2`\> #### Call Signature > **or**\<`T2`\>(`optb`): [`AsyncOption`](AsyncOption.md)\<`T` \| `T2`\> Defined in: [option.ts:191](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L191) ##### Type Parameters ###### T2 `T2` ##### Parameters ###### optb `PromiseLike`\<[`Option`](../type-aliases/Option.md)\<`T2`\>\> ##### Returns [`AsyncOption`](AsyncOption.md)\<`T` \| `T2`\> #### Call Signature > **or**\<`T2`\>(`optb`): [`Option`](../type-aliases/Option.md)\<`T` \| `T2`\> \| [`AsyncOption`](AsyncOption.md)\<`T` \| `T2`\> Defined in: [option.ts:192](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L192) ##### Type Parameters ###### T2 `T2` ##### Parameters ###### optb [`Option`](../type-aliases/Option.md)\<`T2`\> \| `PromiseLike`\<[`Option`](../type-aliases/Option.md)\<`T2`\>\> ##### Returns [`Option`](../type-aliases/Option.md)\<`T` \| `T2`\> \| [`AsyncOption`](AsyncOption.md)\<`T` \| `T2`\> *** ### orElse() > **orElse**\<`T2`\>(`f`): [`Option`](../type-aliases/Option.md)\<`T` \| `T2`\> Defined in: [option.ts:199](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L199) Returns the option if it contains a value, otherwise calls `f` and returns the result. #### Type Parameters ##### T2 `T2` #### Parameters ##### f () => [`Option`](../type-aliases/Option.md)\<`T2`\> #### Returns [`Option`](../type-aliases/Option.md)\<`T` \| `T2`\> *** ### orElseAsync() > **orElseAsync**\<`T2`\>(`f`): [`AsyncOption`](AsyncOption.md)\<`T` \| `T2`\> Defined in: [option.ts:204](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L204) Async version of `orElse`. Returns the option if it contains a value, otherwise calls async `f` and returns the result. #### Type Parameters ##### T2 `T2` #### Parameters ##### f () => `PromiseLike`\<[`Option`](../type-aliases/Option.md)\<`T2`\>\> #### Returns [`AsyncOption`](AsyncOption.md)\<`T` \| `T2`\> *** ### replace() > **replace**(`value`): [`Option`](../type-aliases/Option.md)\<`T`\> Defined in: [option.ts:248](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L248) Sets the option to `Some(value)` and returns its previous state as an `Option`. #### Parameters ##### value `T` #### Returns [`Option`](../type-aliases/Option.md)\<`T`\> *** ### take() > **take**(): [`Option`](../type-aliases/Option.md)\<`T`\> Defined in: [option.ts:238](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L238) Takes the value out of the option, leaving a `None` in its place. #### Returns [`Option`](../type-aliases/Option.md)\<`T`\> *** ### takeIf() > **takeIf**(`predicate`): [`Option`](../type-aliases/Option.md)\<`T`\> Defined in: [option.ts:243](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L243) Takes the value out of the option, but only if the predicate evaluates to `true` on the value. #### Parameters ##### predicate (`val`) => `boolean` #### Returns [`Option`](../type-aliases/Option.md)\<`T`\> *** ### toString() > **toString**(): `string` Defined in: [option.ts:44](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L44) #### Returns `string` *** ### transpose() > **transpose**\<`T`, `E`\>(`this`): [`Result`](../type-aliases/Result.md)\<[`Option`](../type-aliases/Option.md)\<`T`\>, `E`\> Defined in: [option.ts:265](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L265) Transposes an `Option` of a `Result` into a `Result` of an `Option`. Converts `Some(Ok(value))` to `Ok(Some(value))`, `Some(Err(error))` to `Err(error)`, and `None` to `Ok(None)`. #### Type Parameters ##### T `T` ##### E `E` #### Parameters ##### this [`Option`](../type-aliases/Option.md)\<[`Result`](../type-aliases/Result.md)\<`T`, `E`\>\> #### Returns [`Result`](../type-aliases/Result.md)\<[`Option`](../type-aliases/Option.md)\<`T`\>, `E`\> #### Throws `TransposeError` if a `Some` value is not a `Result`. *** ### unwrap() > **unwrap**(): `T` Defined in: [option.ts:79](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L79) Returns the contained `Some` value. #### Returns `T` #### Throws `PanicError` on `None`. *** ### unwrapOr() > **unwrapOr**(`defaultVal`): `T` Defined in: [option.ts:84](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L84) Returns the contained `Some` value or a provided default. #### Parameters ##### defaultVal `T` #### Returns `T` *** ### unwrapOrElse() > **unwrapOrElse**(`f`): `T` Defined in: [option.ts:89](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L89) Returns the contained `Some` value, or calls `f` on `None`. #### Parameters ##### f () => `T` #### Returns `T` *** ### unwrapOrElseAsync() > **unwrapOrElseAsync**(`f`): `Promise`\<`T`\> Defined in: [option.ts:94](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L94) Returns the `Some` value, or awaits `f` on `None`. #### Parameters ##### f () => `PromiseLike`\<`T`\> #### Returns `Promise`\<`T`\> *** ### unzip() > **unzip**\<`T`, `U`\>(`this`): \[[`Option`](../type-aliases/Option.md)\<`T`\>, [`Option`](../type-aliases/Option.md)\<`U`\>\] Defined in: [option.ts:283](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L283) Unzips an `Option` containing a tuple of two values. Returns `[Some(a), Some(b)]` for `Some([a, b])`, or `[None, None]` for `None`. #### Type Parameters ##### T `T` ##### U `U` #### Parameters ##### this [`Option`](../type-aliases/Option.md)\<\[`T`, `U`\]\> #### Returns \[[`Option`](../type-aliases/Option.md)\<`T`\>, [`Option`](../type-aliases/Option.md)\<`U`\>\] *** ### xor() #### Call Signature > **xor**\<`T2`\>(`optb`): [`Option`](../type-aliases/Option.md)\<`T` \| `T2`\> Defined in: [option.ts:209](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L209) Returns `Some` if exactly one of `this`, `optb` is `Some`, otherwise returns `None`. ##### Type Parameters ###### T2 `T2` ##### Parameters ###### optb [`Option`](../type-aliases/Option.md)\<`T2`\> ##### Returns [`Option`](../type-aliases/Option.md)\<`T` \| `T2`\> #### Call Signature > **xor**\<`T2`\>(`optb`): [`AsyncOption`](AsyncOption.md)\<`T` \| `T2`\> Defined in: [option.ts:210](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L210) ##### Type Parameters ###### T2 `T2` ##### Parameters ###### optb `PromiseLike`\<[`Option`](../type-aliases/Option.md)\<`T2`\>\> ##### Returns [`AsyncOption`](AsyncOption.md)\<`T` \| `T2`\> #### Call Signature > **xor**\<`T2`\>(`optb`): [`Option`](../type-aliases/Option.md)\<`T` \| `T2`\> \| [`AsyncOption`](AsyncOption.md)\<`T` \| `T2`\> Defined in: [option.ts:211](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L211) ##### Type Parameters ###### T2 `T2` ##### Parameters ###### optb [`Option`](../type-aliases/Option.md)\<`T2`\> \| `PromiseLike`\<[`Option`](../type-aliases/Option.md)\<`T2`\>\> ##### Returns [`Option`](../type-aliases/Option.md)\<`T` \| `T2`\> \| [`AsyncOption`](AsyncOption.md)\<`T` \| `T2`\> *** ### zip() #### Call Signature > **zip**\<`U`\>(`other`): [`Option`](../type-aliases/Option.md)\<\[`T`, `U`\]\> Defined in: [option.ts:272](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L272) Combines two options into an option containing a tuple of their values. Returns `Some([a, b])` if both options are `Some`, otherwise returns `None`. ##### Type Parameters ###### U `U` ##### Parameters ###### other [`Option`](../type-aliases/Option.md)\<`U`\> ##### Returns [`Option`](../type-aliases/Option.md)\<\[`T`, `U`\]\> #### Call Signature > **zip**\<`U`\>(`other`): [`AsyncOption`](AsyncOption.md)\<\[`T`, `U`\]\> Defined in: [option.ts:273](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L273) ##### Type Parameters ###### U `U` ##### Parameters ###### other `PromiseLike`\<[`Option`](../type-aliases/Option.md)\<`U`\>\> ##### Returns [`AsyncOption`](AsyncOption.md)\<\[`T`, `U`\]\> #### Call Signature > **zip**\<`U`\>(`other`): [`Option`](../type-aliases/Option.md)\<\[`T`, `U`\]\> \| [`AsyncOption`](AsyncOption.md)\<\[`T`, `U`\]\> Defined in: [option.ts:274](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L274) ##### Type Parameters ###### U `U` ##### Parameters ###### other [`Option`](../type-aliases/Option.md)\<`U`\> \| `PromiseLike`\<[`Option`](../type-aliases/Option.md)\<`U`\>\> ##### Returns [`Option`](../type-aliases/Option.md)\<\[`T`, `U`\]\> \| [`AsyncOption`](AsyncOption.md)\<\[`T`, `U`\]\> [**results-ts**](../index.md) *** [results-ts](../index.md) / ResultMethods # Interface: ResultMethods\ Defined in: [result.ts:51](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L51) ## Type Parameters ### T `T` ### E `E` ## Methods ### and() #### Call Signature > **and**\<`U`, `E2`\>(`res`): [`Result`](../type-aliases/Result.md)\<`U`, `E` \| `E2`\> Defined in: [result.ts:194](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L194) Returns `res` if the result is `Ok`, otherwise returns the `Err` value of `self`. JavaScript evaluates the operand before the call. Use `andThen` to compute it only on `Ok`. ##### Type Parameters ###### U `U` ###### E2 `E2` ##### Parameters ###### res [`Result`](../type-aliases/Result.md)\<`U`, `E2`\> ##### Returns [`Result`](../type-aliases/Result.md)\<`U`, `E` \| `E2`\> #### Call Signature > **and**\<`U`, `E2`\>(`res`): [`AsyncResult`](AsyncResult.md)\<`U`, `E` \| `E2`\> Defined in: [result.ts:195](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L195) ##### Type Parameters ###### U `U` ###### E2 `E2` ##### Parameters ###### res `PromiseLike`\<[`Result`](../type-aliases/Result.md)\<`U`, `E2`\>\> ##### Returns [`AsyncResult`](AsyncResult.md)\<`U`, `E` \| `E2`\> #### Call Signature > **and**\<`U`, `E2`\>(`res`): [`Result`](../type-aliases/Result.md)\<`U`, `E` \| `E2`\> \| [`AsyncResult`](AsyncResult.md)\<`U`, `E` \| `E2`\> Defined in: [result.ts:196](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L196) ##### Type Parameters ###### U `U` ###### E2 `E2` ##### Parameters ###### res [`Result`](../type-aliases/Result.md)\<`U`, `E2`\> \| `PromiseLike`\<[`Result`](../type-aliases/Result.md)\<`U`, `E2`\>\> ##### Returns [`Result`](../type-aliases/Result.md)\<`U`, `E` \| `E2`\> \| [`AsyncResult`](AsyncResult.md)\<`U`, `E` \| `E2`\> *** ### andThen() > **andThen**\<`U`, `F`\>(`f`): [`Result`](../type-aliases/Result.md)\<`U`, `E` \| `F`\> Defined in: [result.ts:203](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L203) Calls `f` if the result is `Ok`, otherwise returns the `Err` value of `self`. #### Type Parameters ##### U `U` ##### F `F` #### Parameters ##### f (`val`) => [`Result`](../type-aliases/Result.md)\<`U`, `F`\> #### Returns [`Result`](../type-aliases/Result.md)\<`U`, `E` \| `F`\> *** ### andThenAsync() > **andThenAsync**\<`U`, `F`\>(`f`): [`AsyncResult`](AsyncResult.md)\<`U`, `E` \| `F`\> Defined in: [result.ts:208](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L208) Async version of `andThen`. Calls an async `f` if the result is `Ok`, otherwise returns the `Err` value of `self`. #### Type Parameters ##### U `U` ##### F `F` #### Parameters ##### f (`val`) => `PromiseLike`\<[`Result`](../type-aliases/Result.md)\<`U`, `F`\>\> #### Returns [`AsyncResult`](AsyncResult.md)\<`U`, `E` \| `F`\> *** ### err() > **err**(): [`Option`](../type-aliases/Option.md)\<`E`\> Defined in: [result.ts:88](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L88) Converts from `Result` to `Option`. Returns `Some` for `Err` and `None` for `Ok`. #### Returns [`Option`](../type-aliases/Option.md)\<`E`\> *** ### expect() > **expect**(`msg`): `T` Defined in: [result.ts:166](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L166) Returns the contained `Ok` value. #### Parameters ##### msg `string` #### Returns `T` #### Throws `PanicError` with `msg` and the error value on `Err`. *** ### expectErr() > **expectErr**(`msg`): `E` Defined in: [result.ts:180](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L180) Returns the contained `Err` value. #### Parameters ##### msg `string` #### Returns `E` #### Throws `PanicError` with `msg` and the success value on `Ok`. *** ### flatten() > **flatten**\<`U`, `F`\>(`this`): [`Result`](../type-aliases/Result.md)\<`U`, `E` \| `F`\> Defined in: [result.ts:257](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L257) Unwraps one nested `Result`. The return type includes both error types. #### Type Parameters ##### U `U` ##### F `F` #### Parameters ##### this [`Result`](../type-aliases/Result.md)\<[`Result`](../type-aliases/Result.md)\<`U`, `F`\>, `E`\> #### Returns [`Result`](../type-aliases/Result.md)\<`U`, `E` \| `F`\> #### Throws `FlattenError` if an `Ok` value is not a `Result`. *** ### inspect() > **inspect**(`f`): [`Result`](../type-aliases/Result.md)\<`T`, `E`\> Defined in: [result.ts:135](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L135) Calls a function with a reference to the contained value if `Ok`. Returns the original result. #### Parameters ##### f (`val`) => `void` #### Returns [`Result`](../type-aliases/Result.md)\<`T`, `E`\> *** ### inspectAsync() > **inspectAsync**(`f`): [`AsyncResult`](AsyncResult.md)\<`T`, `E`\> Defined in: [result.ts:140](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L140) Async version of `inspect`. Calls an async function with a reference to the contained value if `Ok`, then returns the original result. #### Parameters ##### f (`val`) => `PromiseLike`\<`void`\> #### Returns [`AsyncResult`](AsyncResult.md)\<`T`, `E`\> *** ### inspectErr() > **inspectErr**(`f`): [`Result`](../type-aliases/Result.md)\<`T`, `E`\> Defined in: [result.ts:147](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L147) Calls a function with a reference to the contained value if `Err`. Returns the original result. #### Parameters ##### f (`err`) => `void` #### Returns [`Result`](../type-aliases/Result.md)\<`T`, `E`\> *** ### inspectErrAsync() > **inspectErrAsync**(`f`): [`AsyncResult`](AsyncResult.md)\<`T`, `E`\> Defined in: [result.ts:152](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L152) Async version of `inspectErr`. Calls an async function with a reference to the contained value if `Err`, then returns the original result. #### Parameters ##### f (`err`) => `PromiseLike`\<`void`\> #### Returns [`AsyncResult`](AsyncResult.md)\<`T`, `E`\> *** ### isErr() > **isErr**(): `this is ErrResult` Defined in: [result.ts:68](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L68) Returns `true` if the result is `Err`. #### Returns `this is ErrResult` *** ### isErrAnd() #### Call Signature > **isErrAnd**\<`F`\>(`f`): `this is ErrResult` Defined in: [result.ts:73](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L73) Returns `true` if the result is `Err` and its value matches the predicate. ##### Type Parameters ###### F `F` ##### Parameters ###### f (`err`) => `err is F` ##### Returns `this is ErrResult` #### Call Signature > **isErrAnd**(`f`): `this is ErrResult` Defined in: [result.ts:74](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L74) ##### Parameters ###### f (`err`) => `boolean` ##### Returns `this is ErrResult` *** ### isOk() > **isOk**(): `this is OkResult` Defined in: [result.ts:57](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L57) Returns `true` if the result is `Ok`. #### Returns `this is OkResult` *** ### isOkAnd() #### Call Signature > **isOkAnd**\<`U`\>(`f`): `this is OkResult` Defined in: [result.ts:62](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L62) Returns `true` if the result is `Ok` and its value matches the predicate. ##### Type Parameters ###### U `U` ##### Parameters ###### f (`val`) => `val is U` ##### Returns `this is OkResult` #### Call Signature > **isOkAnd**(`f`): `this is OkResult` Defined in: [result.ts:63](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L63) ##### Parameters ###### f (`val`) => `boolean` ##### Returns `this is OkResult` *** ### iter() > **iter**(): `Iterable`\<`T`\> Defined in: [result.ts:159](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L159) Returns an iterator over the contained value, or an empty iterator if absent. The iterator yields one value if the result is `Ok`, otherwise none. #### Returns `Iterable`\<`T`\> *** ### map() > **map**\<`U`\>(`f`): [`Result`](../type-aliases/Result.md)\<`U`, `E`\> Defined in: [result.ts:93](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L93) Maps a `Result` to `Result` by applying a function to a contained `Ok` value, leaving an `Err` value untouched. #### Type Parameters ##### U `U` #### Parameters ##### f (`val`) => `U` #### Returns [`Result`](../type-aliases/Result.md)\<`U`, `E`\> *** ### mapAsync() > **mapAsync**\<`U`\>(`f`): [`AsyncResult`](AsyncResult.md)\<`U`, `E`\> Defined in: [result.ts:98](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L98) Async version of `map`. Maps a `Result` to `AsyncResult` by applying an async function to a contained `Ok` value, leaving an `Err` value untouched. #### Type Parameters ##### U `U` #### Parameters ##### f (`val`) => `PromiseLike`\<`U`\> #### Returns [`AsyncResult`](AsyncResult.md)\<`U`, `E`\> *** ### mapErr() > **mapErr**\<`F`\>(`f`): [`Result`](../type-aliases/Result.md)\<`T`, `F`\> Defined in: [result.ts:123](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L123) Maps a `Result` to `Result` by applying a function to a contained `Err` value, leaving an `Ok` value untouched. #### Type Parameters ##### F `F` #### Parameters ##### f (`err`) => `F` #### Returns [`Result`](../type-aliases/Result.md)\<`T`, `F`\> *** ### mapErrAsync() > **mapErrAsync**\<`F`\>(`f`): [`AsyncResult`](AsyncResult.md)\<`T`, `F`\> Defined in: [result.ts:128](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L128) Async version of `mapErr`. Maps a `Result` to `AsyncResult` by applying an async function to a contained `Err` value, leaving an `Ok` value untouched. #### Type Parameters ##### F `F` #### Parameters ##### f (`err`) => `PromiseLike`\<`F`\> #### Returns [`AsyncResult`](AsyncResult.md)\<`T`, `F`\> *** ### mapOr() > **mapOr**\<`U`\>(`fallback`, `f`): `U` Defined in: [result.ts:105](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L105) Returns the fallback on `Err`, or calls `f` with the `Ok` value. JavaScript evaluates the fallback before the call. Use `mapOrElse` to compute it only on `Err`. #### Type Parameters ##### U `U` #### Parameters ##### fallback `U` ##### f (`val`) => `U` #### Returns `U` *** ### mapOrElse() > **mapOrElse**\<`U`\>(`fallbackFn`, `f`): `U` Defined in: [result.ts:110](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L110) Maps a `Result` to `U` by applying fallback function `fallbackFn` to a contained `Err` value, or function `f` to a contained `Ok` value. #### Type Parameters ##### U `U` #### Parameters ##### fallbackFn (`err`) => `U` ##### f (`val`) => `U` #### Returns `U` *** ### mapOrElseAsync() > **mapOrElseAsync**\<`U`\>(`fallbackFn`, `f`): `Promise`\<`U`\> Defined in: [result.ts:115](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L115) Async version of `mapOrElse`. Maps a `Result` to `Promise` by applying async fallback function `fallbackFn` to a contained `Err` value, or async function `f` to a contained `Ok` value. #### Type Parameters ##### U `U` #### Parameters ##### fallbackFn (`err`) => `PromiseLike`\<`U`\> ##### f (`val`) => `PromiseLike`\<`U`\> #### Returns `Promise`\<`U`\> *** ### match() > **match**\<`U`\>(`handlers`): `U` Defined in: [result.ts:272](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L272) Matches the `Result` with two functions, one for each variant. #### Type Parameters ##### U `U` #### Parameters ##### handlers ###### Err (`err`) => `U` ###### Ok (`val`) => `U` #### Returns `U` *** ### ok() > **ok**(): [`Option`](../type-aliases/Option.md)\<`T`\> Defined in: [result.ts:81](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L81) Converts from `Result` to `Option`. Returns `Some` for `Ok` and `None` for `Err`. #### Returns [`Option`](../type-aliases/Option.md)\<`T`\> *** ### or() #### Call Signature > **or**\<`T2`, `F`\>(`res`): [`Result`](../type-aliases/Result.md)\<`T` \| `T2`, `F`\> Defined in: [result.ts:217](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L217) Returns `res` if the result is `Err`, otherwise returns the `Ok` value of `self`. JavaScript evaluates the operand before the call. Use `orElse` to compute it only on `Err`. ##### Type Parameters ###### T2 `T2` ###### F `F` ##### Parameters ###### res [`Result`](../type-aliases/Result.md)\<`T2`, `F`\> ##### Returns [`Result`](../type-aliases/Result.md)\<`T` \| `T2`, `F`\> #### Call Signature > **or**\<`T2`, `F`\>(`res`): [`AsyncResult`](AsyncResult.md)\<`T` \| `T2`, `F`\> Defined in: [result.ts:218](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L218) ##### Type Parameters ###### T2 `T2` ###### F `F` ##### Parameters ###### res `PromiseLike`\<[`Result`](../type-aliases/Result.md)\<`T2`, `F`\>\> ##### Returns [`AsyncResult`](AsyncResult.md)\<`T` \| `T2`, `F`\> #### Call Signature > **or**\<`T2`, `F`\>(`res`): [`Result`](../type-aliases/Result.md)\<`T` \| `T2`, `F`\> \| [`AsyncResult`](AsyncResult.md)\<`T` \| `T2`, `F`\> Defined in: [result.ts:219](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L219) ##### Type Parameters ###### T2 `T2` ###### F `F` ##### Parameters ###### res [`Result`](../type-aliases/Result.md)\<`T2`, `F`\> \| `PromiseLike`\<[`Result`](../type-aliases/Result.md)\<`T2`, `F`\>\> ##### Returns [`Result`](../type-aliases/Result.md)\<`T` \| `T2`, `F`\> \| [`AsyncResult`](AsyncResult.md)\<`T` \| `T2`, `F`\> *** ### orElse() > **orElse**\<`T2`, `F`\>(`f`): [`Result`](../type-aliases/Result.md)\<`T` \| `T2`, `F`\> Defined in: [result.ts:226](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L226) Calls `f` if the result is `Err`, otherwise returns the `Ok` value of `self`. #### Type Parameters ##### T2 `T2` ##### F `F` #### Parameters ##### f (`err`) => [`Result`](../type-aliases/Result.md)\<`T2`, `F`\> #### Returns [`Result`](../type-aliases/Result.md)\<`T` \| `T2`, `F`\> *** ### orElseAsync() > **orElseAsync**\<`T2`, `F`\>(`f`): [`AsyncResult`](AsyncResult.md)\<`T` \| `T2`, `F`\> Defined in: [result.ts:231](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L231) Async version of `orElse`. Calls an async `f` if the result is `Err`, otherwise returns the `Ok` value of `self`. #### Type Parameters ##### T2 `T2` ##### F `F` #### Parameters ##### f (`err`) => `PromiseLike`\<[`Result`](../type-aliases/Result.md)\<`T2`, `F`\>\> #### Returns [`AsyncResult`](AsyncResult.md)\<`T` \| `T2`, `F`\> *** ### toString() > **toString**(): `string` Defined in: [result.ts:52](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L52) #### Returns `string` *** ### transpose() > **transpose**\<`T`, `E`\>(`this`): [`Option`](../type-aliases/Option.md)\<[`Result`](../type-aliases/Result.md)\<`T`, `E`\>\> Defined in: [result.ts:267](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L267) Transposes a `Result` of an `Option` into an `Option` of a `Result`. Converts `Ok(None)` to `None`, `Ok(Some(value))` to `Some(Ok(value))`, and `Err(error)` to `Some(Err(error))`. #### Type Parameters ##### T `T` ##### E `E` #### Parameters ##### this [`Result`](../type-aliases/Result.md)\<[`Option`](../type-aliases/Option.md)\<`T`\>, `E`\> #### Returns [`Option`](../type-aliases/Option.md)\<[`Result`](../type-aliases/Result.md)\<`T`, `E`\>\> #### Throws `TransposeError` if an `Ok` value is not an `Option`. *** ### unwrap() > **unwrap**(): `T` Defined in: [result.ts:173](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L173) Returns the contained `Ok` value. #### Returns `T` #### Throws `PanicError` with the error value on `Err`. *** ### unwrapErr() > **unwrapErr**(): `E` Defined in: [result.ts:187](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L187) Returns the contained `Err` value. #### Returns `E` #### Throws `PanicError` with the success value on `Ok`. *** ### unwrapOr() > **unwrapOr**\<`T2`\>(`fallback`): `T` \| `T2` Defined in: [result.ts:240](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L240) Returns the contained `Ok` value or a provided default. JavaScript evaluates the fallback before the call. Use `unwrapOrElse` to compute it only on `Err`. #### Type Parameters ##### T2 `T2` #### Parameters ##### fallback `T2` #### Returns `T` \| `T2` *** ### unwrapOrElse() > **unwrapOrElse**\<`T2`\>(`f`): `T` \| `T2` Defined in: [result.ts:245](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L245) Returns the contained `Ok` value, or calls `f` with the error. #### Type Parameters ##### T2 `T2` #### Parameters ##### f (`err`) => `T2` #### Returns `T` \| `T2` *** ### unwrapOrElseAsync() > **unwrapOrElseAsync**\<`T2`\>(`f`): `Promise`\<`T` \| `T2`\> Defined in: [result.ts:250](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L250) Returns the `Ok` value, or awaits `f` with the error. #### Type Parameters ##### T2 `T2` #### Parameters ##### f (`err`) => `PromiseLike`\<`T2`\> #### Returns `Promise`\<`T` \| `T2`\> [**results-ts**](../index.md) *** [results-ts](../index.md) / ErrResult # Type Alias: ErrResult\ > **ErrResult**\<`T`, `E`\> = [`ResultMethods`](../interfaces/ResultMethods.md)\<`T`, `E`\> & `object` Defined in: [result.ts:33](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L33) Represents a failed `Result` containing an error of type `E`. ## Type Declaration ### \_isOk > `readonly` **\_isOk**: `false` ## Type Parameters ### T `T` ### E `E` [**results-ts**](../index.md) *** [results-ts](../index.md) / NoneOption # Type Alias: NoneOption\ > **NoneOption**\<`T`\> = [`OptionMethods`](../interfaces/OptionMethods.md)\<`T`\> & `object` Defined in: [option.ts:27](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L27) Represents the absence of a value of type `T`. ## Type Declaration ### \_isSome > `readonly` **\_isSome**: `false` ## Type Parameters ### T `T` [**results-ts**](../index.md) *** [results-ts](../index.md) / OkResult # Type Alias: OkResult\ > **OkResult**\<`T`, `E`\> = [`ResultMethods`](../interfaces/ResultMethods.md)\<`T`, `E`\> & `object` Defined in: [result.ts:26](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L26) Represents a successful `Result` containing a value of type `T`. ## Type Declaration ### \_isOk > `readonly` **\_isOk**: `true` ## Type Parameters ### T `T` ### E `E` [**results-ts**](../index.md) *** [results-ts](../index.md) / Option # Type Alias: Option\ > **Option**\<`T`\> = [`SomeOption`](SomeOption.md)\<`T`\> \| [`NoneOption`](NoneOption.md)\<`T`\> Defined in: [option.ts:41](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L41) `Option` is either `Some(value)` with a value of type `T`, or `None`. Use `match` to handle both variants. Invalid callbacks and operands throw errors. Callback exceptions propagate. `and`, `or`, `xor`, and `zip` return an `AsyncOption` for promise-like operands. They capture the receiver's state at invocation and resolve the operand even when its value is unused. Operand rejections propagate. ## Type Parameters ### T `T` The contained value type. [**results-ts**](../index.md) *** [results-ts](../index.md) / Result # Type Alias: Result\ > **Result**\<`T`, `E`\> = [`OkResult`](OkResult.md)\<`T`, `E`\> \| [`ErrResult`](ErrResult.md)\<`T`, `E`\> Defined in: [result.ts:49](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L49) `Result` is either `Ok(value)` with a value of type `T`, or `Err(error)` with an error of type `E`. Return it for recoverable failures. Invalid callbacks and operands throw errors. Callback exceptions propagate. `and` and `or` return an `AsyncResult` for promise-like operands. They resolve the operand even when its value is unused. Operand rejections propagate. ## Type Parameters ### T `T` The success value type. ### E `E` The error value type. [**results-ts**](../index.md) *** [results-ts](../index.md) / SomeOption # Type Alias: SomeOption\ > **SomeOption**\<`T`\> = [`OptionMethods`](../interfaces/OptionMethods.md)\<`T`\> & `object` Defined in: [option.ts:22](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L22) Represents some value of type `T`. ## Type Declaration ### \_isSome > `readonly` **\_isSome**: `true` ## Type Parameters ### T `T` [**results-ts**](../index.md) *** [results-ts](../index.md) / catchUnwind # Function: catchUnwind() ## Call Signature > **catchUnwind**\<`T`, `Args`\>(`fn`, `onThrow?`): (...`args`) => [`Result`](../type-aliases/Result.md)\<`T`, `unknown`\> Defined in: [result.ts:731](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L731) Wraps `fn` so a return value becomes `Ok(value)` and a thrown value becomes `Err(thrown)`. Use this to adapt functions that throw. Functions with expected failures should return `Result`. Without `onThrow`, the error type is `unknown`. With `onThrow`, its return value becomes the error. The handler receives the thrown value and the original arguments. Exceptions from `onThrow` propagate to the caller. ### Type Parameters #### T `T` #### Args `Args` *extends* `unknown`[] ### Parameters #### fn (...`args`) => `T` The throwing function to wrap. #### onThrow? `undefined` Optional handler invoked when `fn` throws; its return value becomes the `Err` payload. ### Returns A function that captures exceptions from `fn` in a `Result`. (...`args`) => [`Result`](../type-aliases/Result.md)\<`T`, `unknown`\> ## Call Signature > **catchUnwind**\<`T`, `Args`, `E`\>(`fn`, `onThrow`): (...`args`) => [`Result`](../type-aliases/Result.md)\<`T`, `E`\> Defined in: [result.ts:735](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L735) Wraps `fn` so a return value becomes `Ok(value)` and a thrown value becomes `Err(thrown)`. Use this to adapt functions that throw. Functions with expected failures should return `Result`. Without `onThrow`, the error type is `unknown`. With `onThrow`, its return value becomes the error. The handler receives the thrown value and the original arguments. Exceptions from `onThrow` propagate to the caller. ### Type Parameters #### T `T` #### Args `Args` *extends* `unknown`[] #### E `E` ### Parameters #### fn (...`args`) => `T` The throwing function to wrap. #### onThrow (`thrown`, ...`args`) => `E` Optional handler invoked when `fn` throws; its return value becomes the `Err` payload. ### Returns A function that captures exceptions from `fn` in a `Result`. (...`args`) => [`Result`](../type-aliases/Result.md)\<`T`, `E`\> [**results-ts**](../index.md) *** [results-ts](../index.md) / catchUnwindAsync # Function: catchUnwindAsync() ## Call Signature > **catchUnwindAsync**\<`T`, `Args`\>(`fn`, `onThrow?`): (...`args`) => [`AsyncResult`](../interfaces/AsyncResult.md)\<`T`, `unknown`\> Defined in: [async-result.ts:437](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L437) Wraps `fn` so a resolved value becomes `Ok(value)` and a throw or rejection becomes `Err(cause)`. Use this to adapt functions that throw or reject. Functions with expected failures should return `AsyncResult`. Without `onThrow`, the error type is `unknown`. With `onThrow`, its return value becomes the error. The handler receives the cause and the original arguments. Exceptions from `onThrow` reject the returned wrapper. ### Type Parameters #### T `T` #### Args `Args` *extends* `unknown`[] ### Parameters #### fn (...`args`) => `T` \| `PromiseLike`\<`T`\> The throwing/async function to wrap. #### onThrow? `undefined` Optional handler invoked when `fn` throws or rejects; its return value becomes the `Err` payload. ### Returns A function that captures throws and rejections from `fn` in an `AsyncResult`. (...`args`) => [`AsyncResult`](../interfaces/AsyncResult.md)\<`T`, `unknown`\> ## Call Signature > **catchUnwindAsync**\<`T`, `Args`, `E`\>(`fn`, `onThrow`): (...`args`) => [`AsyncResult`](../interfaces/AsyncResult.md)\<`T`, `E`\> Defined in: [async-result.ts:441](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/async-result.ts#L441) Wraps `fn` so a resolved value becomes `Ok(value)` and a throw or rejection becomes `Err(cause)`. Use this to adapt functions that throw or reject. Functions with expected failures should return `AsyncResult`. Without `onThrow`, the error type is `unknown`. With `onThrow`, its return value becomes the error. The handler receives the cause and the original arguments. Exceptions from `onThrow` reject the returned wrapper. ### Type Parameters #### T `T` #### Args `Args` *extends* `unknown`[] #### E `E` ### Parameters #### fn (...`args`) => `T` \| `PromiseLike`\<`T`\> The throwing/async function to wrap. #### onThrow (`thrown`, ...`args`) => `E` Optional handler invoked when `fn` throws or rejects; its return value becomes the `Err` payload. ### Returns A function that captures throws and rejections from `fn` in an `AsyncResult`. (...`args`) => [`AsyncResult`](../interfaces/AsyncResult.md)\<`T`, `E`\> [**results-ts**](../index.md) *** [results-ts](../index.md) / Err # Function: Err() > **Err**\<`E`\>(`error`): [`Result`](../type-aliases/Result.md)\<`never`, `E`\> Defined in: [result.ts:715](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L715) Contains the error value. ## Type Parameters ### E `E` ## Parameters ### error `E` The error to wrap in a failed result. ## Returns [`Result`](../type-aliases/Result.md)\<`never`, `E`\> A `Result` representing a failed outcome. [**results-ts**](../index.md) *** [results-ts](../index.md) / None # Function: None() > **None**\<`T`\>(): [`Option`](../type-aliases/Option.md)\<`T`\> Defined in: [option.ts:895](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L895) No value. ## Type Parameters ### T `T` = `never` ## Returns [`Option`](../type-aliases/Option.md)\<`T`\> An `Option` representing the absence of a value. [**results-ts**](../index.md) *** [results-ts](../index.md) / Ok # Function: Ok() > **Ok**\<`T`\>(`value`): [`Result`](../type-aliases/Result.md)\<`T`, `never`\> Defined in: [result.ts:705](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/result.ts#L705) Contains the success value. ## Type Parameters ### T `T` ## Parameters ### value `T` The value to wrap in a successful result. ## Returns [`Result`](../type-aliases/Result.md)\<`T`, `never`\> A `Result` representing a successful outcome. [**results-ts**](../index.md) *** [results-ts](../index.md) / Some # Function: Some() > **Some**\<`T`\>(`value`): [`Option`](../type-aliases/Option.md)\<`T`\> Defined in: [option.ts:887](https://github.com/madkarmaa/results-ts/blob/c58f1a23b90448049621e08e35753ac39e638895/src/option.ts#L887) Some value of type `T`. ## Type Parameters ### T `T` ## Parameters ### value `T` The value to be wrapped in a `Some`. ## Returns [`Option`](../type-aliases/Option.md)\<`T`\> An `Option` representing the presence of a value.