Skip to content

Commit

Permalink
fix trys not inferring func return type correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethnym committed May 1, 2024
1 parent 1ae5e44 commit 97a6ddc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions trycat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,9 @@ function err<TErr>(error?: TErr): Err<TErr> | Err<void> {
* Calls the given function, catches any thrown error into an {@link Err},
* and wraps the returned value with an {@link Ok} if nothing goes wrong.
*/
function trys(fn: () => void): Result<void, unknown>
function trys<T>(fn: () => T): Result<T, unknown>
function trys<T>(fn: () => T | undefined): Result<void, unknown> | Result<T, unknown> {
function trys(fn: () => void): Result<void, unknown>
function trys<T>(fn: () => T | undefined): Result<T, unknown> | Result<void, unknown> {
try {
const retval = fn()
return retval ? ok(retval) : ok()
Expand Down

0 comments on commit 97a6ddc

Please sign in to comment.