This package strictly contains types. The star of this package is a recursive Pipe type with surprising utility over parameter overloading. These benefits include
- parameter name preservation
- theoritically unlimited functions can be composed (recursive)
- variadic input for both
PipeandCompose - friendly messages on error, pointing to the problem
It's biggest weakness is still stronger than the parameter overloading approach, namely generics on compose functions are not preserved; however, it will accept them and the resulting type will be {}. The overloading approach can actually often fail to compile in those situations.
The main benefit of the overloading approach to this recursive type is that when error occur, the compiler is better able to explain where the error occurred. With this type, in the event of a compile error, the returned type will itself contain information on what went wrong.
Key exported types include
Pipeas mentioned aboveComposedata flows from bottom up ( or left to right )PipeFnPipe applied to create a reference function typeComposeFnCompose applied to create a reference function typePipelineFnPipe applied to create a usefulpipelinefunction type
Other types exported
ExtractFunctionArgumentsextracts function argumentsExtractFunctionReturnValueextracts a functions return type
Ad-hoc types that may aid in constructing applications from these types.
AnyFunctiona type representing any kind of function, an alternative to FunctionAnyFunction1a function representing any function with an arity of 1
npm install pipe-and-compose-types
Example:
import { PipeFn } from 'pipe-and-compose-types'
declare const example: ( first: number, rest: number[] ) => number
declare const pipe: PipeFn
const result = pipe(
example,
String
) // (first: number, rest: number[]) => stringRead more at https://dev.to/babak/introducing-the-recursive-pipe-and-compose-types-3g9o