A declarative approach to error handling in Typescript