Skip to content

Represent "meaningful null" #2049

@swallez

Description

@swallez

[edit 2023-04-03 - rewritten to explain "semantic null" and provide several proposals]

Some fields in the settings API handle null values differently from missing values: sending null resets the setting to their default value, whereas omitting the field just keeps the current value.

We already use SomeType | null in the spec for fields where ES can return null for missing or unknown values. Semantically these are optional values where the ES server doesn't have a if (value == null) test before serializing the field. We added these | null mainly to allow validation tests to pass, even if semantically speaking they should not be there.

We need to distinguish "semantic null" from "null-as-optional".

There are different ways to represent this in the spec:

  • Follow the example of Stringified to represent non-string values that ES can sometimes serialize as strings, and introduce type OptionalNull<T> = T | null:

    • semantic nulls: use SomeType | null.
    • null as optional: replace existing SomeType | null with OptionalNull<SomeType>.
  • Consider that semantic null is important enough to have its own type defined as type NullValue = null:

    • semantic nulls: use SomeType | NullValue
    • null as optional: leave existing SomeType | null as is.
  • Consider that the null value is an encoding concern and that it's really about default values:

    • semantic nulls: use SomeType | Default where type Default = null
    • null as optional: leave existing SomeType | null as is.

    Note: we can also consider Reset instead of Default but this name implies some action rather than a value or state. It makes sense for a request value but not so much for a response value.

  • Something else?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions