Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AR.toOption for undefined promise resolutions resulting in { BS_PRIVATE_NESTED_SOME_NONE: 0 } #96

Open
josh- opened this issue Dec 5, 2023 · 1 comment · May be fixed by #114
Open

Comments

@josh-
Copy link

josh- commented Dec 5, 2023

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)

@JUSTIVE
Copy link
Sponsor

JUSTIVE commented Mar 16, 2024

Hi. I made a PR to resolve this issue. please have a look and let me know if it's right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants