Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Fruits = unionize({
- strawberry: ofType<{ obj1: string }>(),
- banana: ofType<{ obj2: string }>(),
- });
- const Vegetables = unionize({
- lettuce: ofType<{}>(),
- });
- const Produce = unionize({
- fruit: Fruits._Union,
- vegetable: Vegetables._Union,
- });
- type ProduceUnion = typeof Produce._Union;
- // type ProduceUnion = ({
- // tag: "fruit";
- // } & {
- // tag: "strawberry";
- // } & {
- // obj1: string;
- // }) | ({
- // tag: "fruit";
- // } & {
- // tag: "banana";
- // } & {
- // obj2: string;
- // }) | ({
- // tag: "vegetable";
- // } & {
- // tag: "lettuce";
- // })
- const getProduce = (): ProduceUnion => {
- const strawberry1 = Fruits.strawberry({ obj1: 'i' });
- const strawberry = Produce.fruit(strawberry1);
- return strawberry;
- };
- const produce = getProduce();
- console.info(produce); // { obj: 'i', tag: 'fruit' }
Add Comment
Please, Sign In to add comment