unsplash/sum-types

mkConstructor return type can be widened to the entire sum type

samhh opened this issue · 0 comments

samhh commented

Unsure if this is preferable but chucking it here just in case:

function mkConstructor<A extends AnyMember>(k: Tags<A>): (x: Values<A>) => A;
function mkConstructor<A extends AnyMember>(k: Tags<A>): () => A;
function mkConstructor(k: string) {
  return (x: unknown) => ({ [tagKey]: k, [valueKey]: x });
}