unsplash / sum-types

Safe, ergonomic, non-generic sum types in TypeScript.
https://unsplash.github.io/sum-types/
MIT License
42 stars 2 forks source link

mkConstructor return type can be widened to the entire sum type #13

Closed samhh closed 3 years ago

samhh commented 3 years ago

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 });
}