Guest User

Untitled

a guest
Dec 7th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. const Fruits = unionize({
  2. strawberry: ofType<{ obj1: string }>(),
  3. banana: ofType<{ obj2: string }>(),
  4. });
  5.  
  6. const Vegetables = unionize({
  7. lettuce: ofType<{}>(),
  8. });
  9.  
  10. const Produce = unionize({
  11. fruit: Fruits._Union,
  12. vegetable: Vegetables._Union,
  13. });
  14.  
  15. type ProduceUnion = typeof Produce._Union;
  16. // type ProduceUnion = ({
  17. // tag: "fruit";
  18. // } & {
  19. // tag: "strawberry";
  20. // } & {
  21. // obj1: string;
  22. // }) | ({
  23. // tag: "fruit";
  24. // } & {
  25. // tag: "banana";
  26. // } & {
  27. // obj2: string;
  28. // }) | ({
  29. // tag: "vegetable";
  30. // } & {
  31. // tag: "lettuce";
  32. // })
  33.  
  34. const getProduce = (): ProduceUnion => {
  35. const strawberry1 = Fruits.strawberry({ obj1: 'i' });
  36. const strawberry = Produce.fruit(strawberry1);
  37. return strawberry;
  38. };
  39.  
  40. const produce = getProduce();
  41. console.info(produce); // { obj: 'i', tag: 'fruit' }
Add Comment
Please, Sign In to add comment