constResult=Union(['Ok','Err']);constsomething=Result.Ok({stuff:'good stuff'});constmaybe=Result.Err('this is still data');something.match({Ok:({stuff})=>`the ${stuff}`,Err:(msg)=>msg,_:()=>'What?'});// the good stuff
For a better version of that checkout this library.
If you're going to use tags and helper functions, why not go for a little pattern matching too?
Then you can have this.
For a better version of that checkout this library.
Thanks for the suggestion, nice lib :) I use FP-TS and the pattern above is an abstract demonstration of the way of thinking