Skip to content

Commit

Permalink
fix(anzen): throwable type
Browse files Browse the repository at this point in the history
  • Loading branch information
sviridoff committed Sep 18, 2023
1 parent a54de02 commit 5dd5b20
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/anzen/src/anzen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,23 @@ export class Result {
try {
return Result.success(fn());
} catch (err: any) {
return Result.failure(parseErr ? parseErr(err) : err);
return Result.failure(
parseErr ? parseErr(err) : (err as E),
);
}
}

static async fromThrowable<E, T>(
fn: () => Promise<T>,
parseErr?: (err: any) => E,
parseErr?: (err: unknown) => E,
) {
return fn()
.then((value) => {
return Result.success(value);
})
.catch((err) => {
return Result.failure(
parseErr ? parseErr(err) : err,
parseErr ? parseErr(err) : (err as E),
);
});
}
Expand Down

0 comments on commit 5dd5b20

Please sign in to comment.