Thinking with types: using tagged union type in typescript.