practical-fp / union-types

A Typescript library for creating discriminating union types.
MIT License
70 stars 2 forks source link

Improve UX of parameter-less constructor #5

Closed lucasavila00 closed 1 year ago

lucasavila00 commented 1 year ago
export type IconConfig = Variant<"HeroIcon", string> | Variant<"LeadingDotIcon", void>;
const { HeroIcon, LeadingDotIcon } = impl<IconConfig>();
export { HeroIcon, LeadingDotIcon };

LeadingDotIcon(void 0); // today it needs to be called like this
LeadingDotIcon(); // ideally it could be called like this, today is a type error:  Expected 1 arguments, but got 0.ts(2554)

thanks for the awesome lib :)

felixschorer commented 1 year ago

This should work already if you omit the void.

export type IconConfig = Variant<"HeroIcon", string> | Variant<"LeadingDotIcon">;
const { HeroIcon, LeadingDotIcon } = impl<IconConfig>();
export { HeroIcon, LeadingDotIcon };

LeadingDotIcon();