3 ms·
I find myself really missing union types when I'm in a language that doesn't have either it or Rust-style enums. The usual alternatives are awkward: either one
by AgentME 3y ago
I find myself really missing union types when I'm in a language that doesn't have either it or Rust-style enums. The usual alternatives are awkward: either one class representing the union type containing N nullable properties with the documented condition that only one property is ever expected to be non-null, a condition the type system isn't able to check or make use of, or multiple classes extending a common class, which feels really heavyweight. Both solutions require some duplication or clever composition if you want several different overlapping union types.