Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Documenting Js.Undefined #165

Open
johnridesabike opened this issue Apr 13, 2020 · 4 comments
Open

Documenting Js.Undefined #165

johnridesabike opened this issue Apr 13, 2020 · 4 comments
Labels
docs Technical writing

Comments

@johnridesabike
Copy link
Contributor

johnridesabike commented Apr 13, 2020

There are some official Belt functions that use Js.Undefined, but it's not documented on the Reason or BuckleScript docs. The page on option mentions how to use Js.Nullable for interoperability, but not Undefined.

Some questions I have about Js.Undefined.t:

  • Is it obsolete now that option is unboxed?
  • Can you nest it?
  • Can you annotate externals with it as polymorphic instead of a concrete type? (Js.Undefined.t('a))

I had long assumed it was deprecated, but it’s been referenced in a recent BuckleScript blog post. I think that as long as it’s still being officially used on the BuckleScript site, it should be explained in the docs.

I know its API has basic documentation but there’s no explanation as to how it works or what its purpose is.

I would submit a PR myself, but I don't understand the type enough to adequately write about it.

@ryyppy ryyppy added the docs Technical writing label May 2, 2020
@bobzhang
Copy link
Collaborator

bobzhang commented May 4, 2020

There are some official Belt functions that use Js.Undefined

The reason is that nested Undefined is flattened which is contrary to option so that the generated code is slightly better than the option.

Is it obsolete now that option is unboxed?

It's less used when you don't care about perf or code size or in non-polymorphic code

Can you nest it?

Undefined is flattened contrary to option

Can you annotate externals with it as polymorphic instead of a concrete type? (Js.Undefined.t('a))

I am not sure I fully get the question, why it is problematic here?

@cristianoc
Copy link
Contributor

Can you annotate externals with it as polymorphic instead of a concrete type? (Js.Undefined.t('a))

I am not sure I fully get the question, why it is problematic here?

I think that such a binding can be unsound precisely because of flattening. Or, just with "surprising behaviour".

@johnridesabike
Copy link
Contributor Author

Can you annotate externals with it as polymorphic instead of a concrete type? (Js.Undefined.t('a))

I am not sure I fully get the question, why it is problematic here?

I’m thinking of the caveats listed on the Reason docs for option:

  • Never, EVER, pass a nested option value (e.g. Some(Some(Some(5)))) into the JS side.
  • Never, EVER, annotate a value coming from JS as option('a). Always give the concrete, non-polymorphic type.

The second one in particular. Do these apply to Js.undefined the same way?

@bobzhang
Copy link
Collaborator

bobzhang commented May 6, 2020 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
docs Technical writing
Projects
None yet
Development

No branches or pull requests

4 participants