Skip to catalogue

275

option type

also Option, Maybe, null vs undefined

Missing, null, and empty are three states. Do not collapse them at the door.

What is option type?

An option type is a value that is present or absent, and the caller has to handle both. JSON adds a third: a field left out, a field set to null, and a field set to empty string are different. undefined and null are different in JavaScript. Coalescing them with a default at the parser throws away what the client sent.

Why does option type matter when vibe coding?

The draft uses `value ?? default` on a PATCH body. A client that sent null to clear a field, and a client that omitted the field, become the same. The clear never happens, or every omit clears.

How do you do option type?

Represent absence in the type. At a JSON boundary, decide absent versus null on purpose and test both. Do not optional-chain past a bug so the screen renders blank.

How do you ask a model for option type?

Represent (field) as an option. On input, treat a missing field and null as different cases. Do not coalesce them with a default. Handle the absent case at the call site.

What goes wrong with option type?

An optional field on the domain type because the parser was unsure. The uncertainty leaked into every caller.

adjacent