supermacro / neverthrow

Type-Safe Errors for JS & TypeScript
MIT License
4.04k stars 85 forks source link

OrElse callback should be able to change Ok type #484

Closed braxtonhall closed 2 months ago

braxtonhall commented 1 year ago

Unfortunately this would be a breaking change, as anyone who explicitly annotated the types like orElse<A>(foo) will need to update their code to orElse<U, A>(foo)

supermacro commented 1 year ago

https://github.com/supermacro/neverthrow/issues/496

myftija commented 1 year ago

@supermacro Any updates on this? Would be really great to have this behavior for orElse :)

jdisho commented 11 months ago

+1

changeset-bot[bot] commented 3 months ago

🦋 Changeset detected

Latest commit: 378b3e530dd41ff6c2cb9a71e8b9c0b5feacc74e

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

This PR includes changesets to release 1 package | Name | Type | | ---------- | ----- | | neverthrow | Major |

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

braxtonhall commented 3 months ago

It is possible to make this PR not a breaking change

- orElse<U, A>(f: (e: E) => Result<U, A> | ResultAsync<U, A>): ResultAsync<U | T, A>
+ orElse<A, U = T>(f: (e: E) => Result<U, A> | ResultAsync<U, A>): ResultAsync<U | T, A>

That way anyone who has already explicitly annotated the type arguments res.orElse<Foo>(..) will have the same behaviour as before.

The downside is of course that this is really awkward to use, especially as it swaps the order or the ok value type and the err value type. I would guess that would be super error prone and surprising to users.

supermacro commented 2 months ago

I think it's OK for this to be implemented as a breaking change.

Actions:

braxtonhall commented 2 months ago

I think it's OK for this to be implemented as a breaking change.

Actions:

  • please include a changeset file
  • resolve merge conflicts
  • update docs here and here

Done! (i think)