neverthrow icon indicating copy to clipboard operation
neverthrow copied to clipboard

Fix combineWithAllErrors types

Open braxtonhall opened this issue 2 years ago • 1 comments

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.

braxtonhall avatar Jun 27 '23 10:06 braxtonhall

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

supermacro avatar Oct 09 '23 10:10 supermacro