supermacro / neverthrow

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

Fix combineWithAllErrors types #483

Closed braxtonhall closed 2 months ago

braxtonhall commented 1 year ago

combineWithAllErrors provides types that are not necessarily correct.

const foo: Result<"a", "b"> = ok("a");
const bar: Result<"c", "d"> = err("d");
Result.combineWithAllErrors([foo, bar]).mapErr((errors) => {
    errors satisfies ["b", "d"]; // should NOT satisfy, but DOES :/
    console.log(errors); // logs ['d'] despite having type ['b', 'd']

    const [b] = errors;
    b satisfies "b"; // should NOT satisfy, but DOES :/
    console.log(b); // logs 'd' despite having type "b"
});

The documentation actually correctly matches the implementation, but the type declarations are a little off. In the types, if a literal array is provided, the Results are given to TraverseWithAllErrors which preserves the error order.

supermacro commented 1 year ago

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

m-shaka commented 3 months ago

@braxtonhall Hi, this PR looks nice. Can you resolve conflicts?

changeset-bot[bot] commented 3 months ago

🦋 Changeset detected

Latest commit: ecc25b956e1982a61190a846b42d87c6bec6a24e

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

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

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

@braxtonhall Hi, this PR looks nice. Can you resolve conflicts?

@m-shaka resolved!