From 406cbb6fd4077aa79bc67337d70f987e3adc7622 Mon Sep 17 00:00:00 2001 From: front-depiction <96551451+front-depiction@users.noreply.github.com> Date: Wed, 30 Apr 2025 21:07:46 +0200 Subject: [PATCH] Update result.ts to improve type inference in function parameters --- src/result.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/result.ts b/src/result.ts index ad447caa..f1834f14 100644 --- a/src/result.ts +++ b/src/result.ts @@ -20,19 +20,19 @@ export namespace Result { * @param errorFn when an error is thrown, this will wrap the error result if provided */ // eslint-disable-next-line @typescript-eslint/no-explicit-any - export function fromThrowable any, E>( - fn: Fn, - errorFn?: (e: unknown) => E, - ): (...args: Parameters) => Result, E> { - return (...args) => { - try { - const result = fn(...args) - return ok(result) - } catch (e) { - return err(errorFn ? errorFn(e) : e) - } + export function fromThrowable( + fn: (...args: A) => R, + errorFn?: (e: unknown) => E, +): (...args: A) => Result { + return (...args: A) => { + try { + const result = fn(...args); + return ok(result); + } catch (e) { + return err(errorFn ? errorFn(e) : e); } - } + }; +} export function combine< T extends readonly [Result, ...Result[]]