Right now, ADT fixes the discriminant field to _type. This works great, but it should be easy to generalize this, and allow users to supply their own discriminant field. potentially something like:
MakeADT<D extends string, T extends Record<string, {}>> = {
[K in keyof T]: Record<D, K> & T[K];
}[keyof T];
type Option<A> = MakeADT<'_tag', {
some: { value: A },
none: {}
}>
and now Option is:
type Option<A> =
| { _tag: "some", value: A }
| { _tag: "none" }
Right now,
ADT
fixes the discriminant field to_type
. This works great, but it should be easy to generalize this, and allow users to supply their own discriminant field. potentially something like:and now
Option
is: