Refactoring TypeScript code with flatMap

Published --