For a prime example of this, take a look at the type definition for the ramda pipe function: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/mast...
It's a hard coded list of 10 signature overrides that allows it to support up to 10 piped functions. Obviously the actual ramda pipe function can support an arbitrary number of piped functions at runtime, but the types as written only supports 10.
This seems awfully inelegant and inflexible. I assume there is some fundamental deficiency in TypeScript's type system that forces people to specify types this way, otherwise it would have been rewritten by now.
Is higher kinded types what's missing to be able to express higher order functions and functional composition in an elegant way? If so, can someone provide an example of what the type signature of a pipe function would look like with higher kinded types? Any ideas if higher kinded types are being considered as additions in future versions of TypeScript, or if that's even feasible at all?
In Haskell I believe when you write fn :: a -> b
a can be inferred to be (Int -> Int -> Int), say.
Here when you write pipe<A, B>(A => B): A => B
'A => B' just means a function from one-arg A to one-arg B.
The solution is some sort of type-level function, but it also requires new sorts of type variables.
Like composition: `f . g . h $ a`
It adds inference for higher order functions, and, from a bit of playing with the Typescript nightly build, ramda works much better. Once 3.4 comes out it's going to make life a lot easier for ramda/functional/clojure-like programming
[1] https://github.com/DefinitelyTyped/DefinitelyTyped/blob/mast...