Skip to content

O.Option's functions with null literal value behaves differ from with undefined literal values #97

@JUSTIVE

Description

@JUSTIVE

From the type definition of O.Option<A> = A|null|undefined, where A is regarded as Some<A>, and null | undefined as None, I thought that literal null values should behave the same as undefined literal values.

I've just written some examples from ts-belt's live editor.

nullish values O.match O.isNone
null image image
undefined image image

for example, the O.match is described as follows, where the null value could passed into someFn.

function _match(option, someFn, noneFn) {
  if (option !== undefined) {
    return someFn(Caml_option.valFromOption(option));
  } else {
    return noneFn(undefined);
  }
}

and O.isNone seems generated from the gentype utility from the rescript-compiler.

I found that O.fromNullable for every null occurring situation, but it's very cumbersome, and so unintuitive because of O.Option's type mismatches with these behaviors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions