Skip to main content
Module

x/domain_functions/src/domain-functions.ts>safeResult

Decouple your business logic from your framework. With first-class type inference from end to end.
Go to Latest
function safeResult
import { safeResult } from "https://deno.land/x/domain_functions@v2.6.0/src/domain-functions.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>>