Effect CommunityEC
Effect Community3y ago
73 replies
ts

Modeling a Type with Multiple Requirements

Modeling question: How would you represent a type where, e.g. it requires a or b, c or d, e or f, etc? I don't just want to have
type Foo = {
  a?: A;
  b?: B;
  c?: C;
  // ...
};

and handle the requirements in logic, but I'm worried about the complexity of this:
type WithA = {a: A; b?: B};
type WithB = {a?: A; b: B};
type WithC = {c: C; d?: D};
type WithD = {c?: C; d: D};
// ...
type Foo = (WithA | WithB) & (WithC | WithD);

(It doesn't even represent the complete truth, since I would sorta need a cartesian product)
Ideas?
Was this page helpful?