This is a version of the talk Railway Oriented Programming by Scott Wlaschin. While the original language of the talk is F#, this version has been translated to TypeScript, because the concept can be easily applied to TypeScript programming as well, and the metaphor used is phenomenal.
A useful library for attempts in this direction is fp-ts for the result type and for composition
Scott Wlaschin 2014