Open josh- opened 8 months ago
When using the new AR functions, we've run into a scenario when calling AR.toOption on a promise that has resolved undefined will result in the underlying value being { BS_PRIVATE_NESTED_SOME_NONE: 0 } (where O.None would instead be expected).
AR
AR.toOption
undefined
{ BS_PRIVATE_NESTED_SOME_NONE: 0 }
O.None
For example:
const toOptionTest = async () => { const option = await pipe(AR.resolve(undefined), AR.toOption); console.log('option is:', option); O.match( option, () => { console.log('option is `Some`'); }, () => { console.log('option is `None`'); }, ); return option; }; void toOptionTest();
In the above, option is inferred by the Typescript compiler to be O.Option<undefined>, however the following is printed:
option
O.Option<undefined>
2023-12-06 09:15:04 option is: { BS_PRIVATE_NESTED_SOME_NONE: 0 } 2023-12-06 09:15:04 option is `Some`
I would instead expect the "option is `None`" log line to be printed, and the someFn branch of O.match not to have been called.
someFn
O.match
This appears to be an underlying Rescript value which is returned by AR.toOption because Some(value) is called here even if the value is None:
Some(value)
None
https://github.com/mobily/ts-belt/blob/c825d9709de1e5d15b1b362429e0cee56c96c516/src/AsyncResult/AsyncResult.res#L70-L72
Hi. I made a PR to resolve this issue. please have a look and let me know if it's right.
When using the new
AR
functions, we've run into a scenario when callingAR.toOption
on a promise that has resolvedundefined
will result in the underlying value being{ BS_PRIVATE_NESTED_SOME_NONE: 0 }
(whereO.None
would instead be expected).For example:
In the above,
option
is inferred by the Typescript compiler to beO.Option<undefined>
, however the following is printed:I would instead expect the "option is `None`" log line to be printed, and the
someFn
branch ofO.match
not to have been called.This appears to be an underlying Rescript value which is returned by
AR.toOption
becauseSome(value)
is called here even if the value isNone
:https://github.com/mobily/ts-belt/blob/c825d9709de1e5d15b1b362429e0cee56c96c516/src/AsyncResult/AsyncResult.res#L70-L72