-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OrElse callback should be able to change Ok type #484
Conversation
@supermacro Any updates on this? Would be really great to have this behavior for |
+1 |
🦋 Changeset detectedLatest commit: 378b3e5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
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 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@supermacro if the PR is merged, changesets will create the release PR of v8.0.0.
I'll leave the timing of the merge up to you.
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [neverthrow](https://github.com/supermacro/neverthrow) | dependencies | major | [`7.2.0` -> `8.0.0`](https://renovatebot.com/diffs/npm/neverthrow/7.2.0/8.0.0) | --- ### Release Notes <details> <summary>supermacro/neverthrow (neverthrow)</summary> ### [`v8.0.0`](https://github.com/supermacro/neverthrow/blob/HEAD/CHANGELOG.md#800) [Compare Source](supermacro/neverthrow@v7.2.0...v8.0.0) ##### Major Changes - [#​484](supermacro/neverthrow#484) [`09faf35`](supermacro/neverthrow@09faf35) Thanks [@​braxtonhall](https://github.com/braxtonhall)! - Allow orElse method to change ok types. This makes the orElse types match the implementation. This is a breaking change for the orElse type argument list, as the ok type must now be provided before the err type. ```diff - result.orElse<ErrType>(foo) + result.orElse<OkType, ErrType>(foo) ``` This only applies if type arguments were explicitly provided at an orElse callsite. If the type arguments were inferred, no updates are needed during the upgrade. </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC43Ny41IiwidXBkYXRlZEluVmVyIjoiMzguODAuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiZGVwZW5kZW5jaWVzIl19--> Reviewed-on: https://git.tristess.app/alexandresoro/ouca/pulls/116 Reviewed-by: Alexandre Soro <[email protected]> Co-authored-by: renovate <[email protected]> Co-committed-by: renovate <[email protected]>
Unfortunately this would be a breaking change, as anyone who explicitly annotated the types like
orElse<A>(foo)
will need to update their code toorElse<U, A>(foo)