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).
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:
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.
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:
|
promise->thenResolve(option => { |
|
switch option { |
|
| Ok(value) => Some(value) |
When using the new
ARfunctions, we've run into a scenario when callingAR.toOptionon a promise that has resolvedundefinedwill result in the underlying value being{ BS_PRIVATE_NESTED_SOME_NONE: 0 }(whereO.Nonewould instead be expected).For example:
In the above,
optionis 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
someFnbranch ofO.matchnot to have been called.This appears to be an underlying Rescript value which is returned by
AR.toOptionbecauseSome(value)is called here even if the value isNone:ts-belt/src/AsyncResult/AsyncResult.res
Lines 70 to 72 in c825d97