diff --git a/src/result.ts b/src/result.ts index e0985c0..b19f0a8 100644 --- a/src/result.ts +++ b/src/result.ts @@ -96,9 +96,9 @@ export class Result { * @returns `Ok` with the resolved value or `Err` with the exception error or the rejected value. */ public static async tryAsync( - fn: (...args: TArgs) => T, + fn: (...args: TArgs) => T | Promise, ...args: TArgs - ): Promise> { + ): Promise, E>> { try { return Result.Ok(await fn(...args)); } catch (error: any) { diff --git a/test/result.test.ts b/test/result.test.ts index 813c926..2cb65da 100644 --- a/test/result.test.ts +++ b/test/result.test.ts @@ -114,7 +114,8 @@ describe("Result", () => { expect(result).toBeInstanceOf(Result); expect(result.isOk()).toBe(true); expect(result.isErr()).toBe(false); - expect(result.unwrap()).toBe(42); + const value: number = result.unwrap(); + expect(value).toBe(42); }); it("should return an Err result if the function throws an error", async () => {