diff --git a/lib/result.ts b/lib/result.ts index 8649a2468..77431f5ee 100644 --- a/lib/result.ts +++ b/lib/result.ts @@ -1,5 +1,13 @@ /** - * @ignore + * A value representing either a successful outcome or an error. + * + * `Result` is used in APIs when you want to preserve both successes and + * failures instead of short-circuiting on the first error. + * + * A successful result has the shape `{ ok: true, value }` and a failed result + * has the shape `{ ok: false, error }`. + * + * @since 4.1 */ export type Result = { readonly ok: true; @@ -10,7 +18,18 @@ export type Result = { }; /** - * @ignore + * Construct a successful {@link Result}. + * + * ### Example + * + * ```javascript + * import { Ok } from 'effection'; + * + * let result = Ok("hello"); + * // { ok: true, value: "hello" } + * ``` + * + * @since 4.1 */ export function Ok(): Result; export function Ok(value: T): Result; @@ -22,7 +41,18 @@ export function Ok(value?: T): Result { } /** - * @ignore + * Construct a failed {@link Result}. + * + * ### Example + * + * ```javascript + * import { Err } from 'effection'; + * + * let result = Err(new Error("oh no")); + * // { ok: false, error: Error("oh no") } + * ``` + * + * @since 4.1 */ export const Err = (error: Error): Result => ({ ok: false, error });