loading...

re: Creating a typed "compose" function in TypeScript VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Hey Matt, Thanks for your article! I am having a question I don't really understand: In my understanding, the compose function can compose functi...
 

Hi Sebastian,
This isn't as smart as that: it expects that they all return the same type. If be interested to see if there's a way of typing the other sort though.

 

Hey Matt,

the only way I see it is via N+1 different generic types - though that is ofc. not as nice as your generic implementation.

See:

All the best, Sebastian

Yeah, I can't see any way that doesn't boil down to "use lots of repetitive overloads"

 

If you use infix operators (read: ascii art method names) you can get typing of composed functions with different signatures, without overloading:

Compose and pipe "infix operators"

With the downside that you can't just spread an array of functions into compose like you can with yours.

code of conduct - report abuse