Currently, I am developing a Node.js module with Flow typing that follows this structure:
hole(obj)
.pipe(fn1)
.pipe(fn2)
.pipe(fn3);
The expected type definition would look something like this:
/* It's not working */
hole(T)
.pipe((T) => U)
.pipe((U) => V)
.pipe((V) => W)
I'm uncertain if it is even possible to accurately define the types.
Currently, the functions are defined as pipe(fn: (any => any)): Hole
. I believe I need to specify the return types of the functions more precisely than just any
. I attempted to tighten the type definitions of the instance method as shown below, but I was unsuccessful:
/* This is not working */
class Hole {
pipe(fn: (T => U)): (Hole & {pipe: (U => V)}))
}
Do you think it is feasible in JavaScript to use type tools for this purpose? If TypeScript can provide a solution instead of Flow, I would be open to switching. Additionally, I am curious about how Java's Stream tackles this issue.