neverthrow
neverthrow copied to clipboard
Fix combineWithAllErrors types
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.
https://github.com/supermacro/neverthrow/issues/496