buildo / metarpheus-io-ts

Generate domain models and client interpreting metarpheus output
MIT License
7 stars 1 forks source link

Handle tagged unions with fewer than two cases #115

Closed tpetrucciani closed 4 years ago

tpetrucciani commented 4 years ago

Code generation for tagged unions currently works only when they have at least two cases (otherwise, it generates invalid code). However, tagged unions with fewer than two cases are used in our code and can make sense.

Specifically, we sometimes use them to represent error types for uniformity with those with more cases: one case for a single kind of error, zero if the route cannot give errors.

Metarpheus generates the usual model:

{
  "name": "ErrorTraitName",
  "values": [
    {
      "name": "ClassOrObjectExtendingErrorTraitName",
      "params": [ ... ],
      "isValueClass": false
    }
  ],
  "package": [ ... ],
  "_type": "TaggedUnion"
}

The zero-case variant (empty values) could possibly be just a synonym for never.

From https://github.com/buildo/retro/issues/107.