3 ms·
It is possible (and popular) to have sum types in TypeScript by manually adding a tag, though. type Maybe<T> = | { kind: "Some", value: T } | { kind:
by paavohtl 6y ago
It is possible (and popular) to have sum types in TypeScript by manually adding a tag, though.
type Maybe<T> =
| { kind: "Some", value: T }
| { kind: "None" }
- carlmr 6y agoThis is also why sum types are often referred to as tagged unions. They are a special case of a union, in Rust's case with support from the type system.
- a_humean 6y agoYep, Typescript's control flow analysis, type literals, and union types allow us have tagged unions/sum types. Probably its best feature.