typescript-result icon indicating copy to clipboard operation
typescript-result copied to clipboard

Result.ok(0) leads to result.value == null

Open GaelGC opened this issue 4 years ago • 1 comments

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 ?

GaelGC avatar Jun 14 '21 17:06 GaelGC

I just encountered this behaviour, and got super confused about it... Is it going to be addressed?

Pamplemousse avatar Feb 07 '24 07:02 Pamplemousse

This should be fixed in the latest version (v2).

everweij avatar Jun 09 '24 13:06 everweij