Skip to content

Commit

Permalink
Added JS Doc forinline documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Inalegwu committed Sep 16, 2024
1 parent f64b0d4 commit 3de10e2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import {type Result,ok,err} from "npm:[email protected]";
type AnyFunction=(...args:any[])=>any;

/**
* Wraps a function that could possibly throw
* and returns a new function that uses Result<T,E>
* to ensure errors are handled
*
* @template F the type of the function to wrap
* @param fn The Function being wrapped
* @returns A new function that returns a Result Type
*
*
**/
export function makeSafeFunction<F extends AnyFunction>(fn:F):(...args:Parameters<F>)=>Result<ReturnType<F> extends Promise<infer R>?R:ReturnType<F>,Error>{
// @ts-ignore: still yet to figure this out but it works
Expand Down

0 comments on commit 3de10e2

Please sign in to comment.