Skip to content

Commit

Permalink
fix(result): tryAsync typing
Browse files Browse the repository at this point in the history
  • Loading branch information
crimx committed Nov 28, 2024
1 parent 663fceb commit 18233f1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ export class Result<T = any, E = any> {
* @returns `Ok` with the resolved value or `Err` with the exception error or the rejected value.
*/
public static async tryAsync<T = any, E = any, TArgs extends any[] = []>(
fn: (...args: TArgs) => T,
fn: (...args: TArgs) => T | Promise<T>,
...args: TArgs
): Promise<Result<T, E>> {
): Promise<Result<Awaited<T>, E>> {
try {
return Result.Ok(await fn(...args));
} catch (error: any) {
Expand Down
3 changes: 2 additions & 1 deletion test/result.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 18233f1

Please sign in to comment.