-
-
Notifications
You must be signed in to change notification settings - Fork 503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion: recursive pipe / compose types #822
Comments
@babakness thanks for sharing p.s. FYI Looks like there's some issue with polymorphic functions import { head } from 'fp-ts/lib/Array'
import { pipe } from 'fp-ts/lib/function'
import { lift } from 'fp-ts/lib/Functor'
import { option } from 'fp-ts/lib/Option'
const toPair = <A>(a: A): [A, A] => [a, a]
const liftedToPair = lift(option)(toPair)
// f: <A>(a: A[]) => Option<[A, A]>
const f = pipe(
head,
liftedToPair
)
import { pipe as pipe2 } from 'pipe-and-compose'
// f2: (as: {}[]) => Option<[{}, {}]>
const f2 = pipe2(head, liftedToPair) |
@gcanti thanks for noticing this. I see that as of the latest TS 3.4+, overloading I believe the support needed by the compiler for a recursive version such as mine is for /**
* Extracts function arguments
*/
export type ExtractFunctionArguments < Fn > = Fn extends ( ...args: infer P ) => any ? P : never
/**
* Extracts function return values
*/
export type ExtractFunctionReturnValue<Fn> = Fn extends ( ...args: any[] ) => infer P ? P : never I'll keep an eye out for this. I created a feature request for this at TypeScript's repo: |
The linked issue microsoft/TypeScript#30887 closed 8 days ago 👀 Does this mean we're unblocked in terms of offering a |
Hi, I did some work recently on the
Pipe
andCompose
types. I have an approach that uses a recursive type to deliver better typings on composed functions. For example, parameter names are preserved.Here is a link the repo with the types
https://github.com/babakness/pipe-and-compose-types
Here is a link to the implementation:
https://github.com/babakness/pipe-and-compose
Related article:
https://dev.to/babak/introducing-the-recursive-pipe-and-compose-types-3g9o
--
There is good reason to keep the these types in an external repo. TypeScript's compiler seems treat them better that way.
All the best.
The text was updated successfully, but these errors were encountered: