From aa10373292bb9db4f014a4613d52f66793bc77ef Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Sat, 28 Jun 2025 16:08:07 +1000 Subject: [PATCH] feat(ui): loosen typings for Result --- invokeai/frontend/web/src/common/util/result.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/invokeai/frontend/web/src/common/util/result.ts b/invokeai/frontend/web/src/common/util/result.ts index e79d03122c..d980459f64 100644 --- a/invokeai/frontend/web/src/common/util/result.ts +++ b/invokeai/frontend/web/src/common/util/result.ts @@ -57,7 +57,7 @@ export class Err { * @template T The type of the value in the `Ok` case. * @template E The type of the error in the `Err` case. */ -type Result = Ok | Err; +type Result = Ok | Err; /** * Creates a successful result. @@ -85,11 +85,12 @@ export function ErrResult(error: E): Err { * @param {() => T} fn The function to execute. * @returns {Result} An `Ok` result if the function succeeds, or an `Err` result if it throws an error. */ -export function withResult(fn: () => T): Result { +/* eslint-disable-next-line @typescript-eslint/no-explicit-any */ +export function withResult(fn: () => T): Result { try { return new Ok(fn()); } catch (error) { - return new Err(error instanceof Error ? error : new Error(String(error))); + return new Err(error); } } @@ -99,11 +100,12 @@ export function withResult(fn: () => T): Result { * @param {() => Promise} fn The asynchronous function to execute. * @returns {Promise>} A `Promise` resolving to an `Ok` result if the function succeeds, or an `Err` result if it throws an error. */ -export async function withResultAsync(fn: () => Promise): Promise> { +/* eslint-disable-next-line @typescript-eslint/no-explicit-any */ +export async function withResultAsync(fn: () => Promise): Promise> { try { const result = await fn(); return new Ok(result); } catch (error) { - return new Err(error instanceof Error ? error : new Error(String(error))); + return new Err(error); } }