Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/domain_functions/src/constructor.ts>safeResult

Types and functions to make composition easy and safe
Latest
function safeResult
import { safeResult } from "https://deno.land/x/domain_functions@v3.0.0/src/constructor.ts";

A functions that turns the result of its callback into a Result object.

Examples

const result = await safeResult(() => ({ message: 'hello', })) // the type of result is Result<{ message: string }> if (result.success) { console.log(result.data.message) }

const result = await safeResult(() => { throw new Error('something went wrong') }) // the type of result is Result if (!result.success) { console.log(result.errors[0].message) }

Parameters

fn: () => T

Returns

Promise<Result<T>>