typescript-result
typescript-result copied to clipboard
Result.ok(0) leads to result.value == null
When running the following code:
function a(): Result<number, number> {
return Result.ok(0);
}
const x = a();
if (x.isSuccess()) {
console.log(x.value);
}
leads to null being printed.
After looking at Result.ok, it seems to be because the recorder value is value || null, which becomes null due to 0 not being truthy.
The documentation doesn't seem talk about it. Did I miss something or is returning "", false or 0 not compatible with the library ?
I just encountered this behaviour, and got super confused about it... Is it going to be addressed?
This should be fixed in the latest version (v2).