-
Notifications
You must be signed in to change notification settings - Fork 108
Description
[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 introducetype OptionalNull<T> = T | null
:- semantic nulls: use
SomeType | null
. - null as optional: replace existing
SomeType | null
withOptionalNull<SomeType>
.
- semantic nulls: use
-
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.
- semantic nulls: use
-
Consider that the
null
value is an encoding concern and that it's really about default values:- semantic nulls: use
SomeType | Default
wheretype Default = null
- null as optional: leave existing
SomeType | null
as is.
Note: we can also consider
Reset
instead ofDefault
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. - semantic nulls: use
-
Something else?