neverthrow icon indicating copy to clipboard operation
neverthrow copied to clipboard

prevent passing a specific error type for `.fromThrowable` without providing an error mapping function

Open boyeln opened this issue 1 year ago • 1 comments

As discussed in https://github.com/supermacro/neverthrow/pull/567#discussion_r1754313850, the current type signature of fromThrowable allows users to pass a specific error value type, without providing an error mapping function that produces the provided error type:

const safeParse = Result.fromThrowable<typeof JSON.parse, number>(JSON.parse);
      // ^ (text: string, reviver?: (this: any, key: string, value: any) => any) => Result<any, number>

This PR tries to solve that by adding some overloads to the function, only allowing users to specify the error type when a matching error mapping function is provided.

boyeln avatar Sep 12 '24 18:09 boyeln

🦋 Changeset detected

Latest commit: 2815b6fddd984c668ed0ca48c62bd3841921129d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
neverthrow Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Sep 12 '24 18:09 changeset-bot[bot]