Closed lucasavila00 closed 1 year ago
Instead of augmenting match
I would change the signature of the renderIcon
function.
type LabelConfig =
| Variant<"TextAndIcon", string>
| Variant<"JustIcon", string>
| Variant<"JustText", { text: string; icon: string }>;
type IconVariant = Narrow<LabelConfig, "TextAndIcon" | "JustIcon">;
const renderIcon = (icon: IconVariant) => {
return "...";
};
const current = (cfg: LabelConfig) => {
if (JustText.is(cfg)) return <></>;
return renderIcon(cfg);
};
I stumbled across this situation, which union-types kinda couldn't handle:
Is the proposed addition ok? I've been using it on my fork and could upstream the change if you like it.