Creating a typed "compose" function in TypeScript 3