[fabric/core] Add variantConstructor utility for tagged variants

This commit is contained in:
Pablo Baleztena 2024-10-21 13:02:26 -03:00
parent 65432d1c54
commit ab41ff028d
2 changed files with 15 additions and 0 deletions

View File

@ -0,0 +1,14 @@
import type { TaggedVariant, VariantTag } from "./variant.ts";
export function variantConstructor<
const T extends TaggedVariant<string>,
>(
tag: T[VariantTag],
) {
return <TOpts extends Omit<T, VariantTag>>(options: TOpts) => {
return {
_tag: tag,
...options,
} as const;
};
}

View File

@ -1,2 +1,3 @@
export * from "./constructor.ts";
export * from "./match.ts"; export * from "./match.ts";
export * from "./variant.ts"; export * from "./variant.ts";