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
Pipe
andCompose
- 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
Pipe
as mentioned aboveCompose
data flows from bottom up ( or left to right )PipeFn
Pipe applied to create a reference function typeComposeFn
Compose applied to create a reference function typePipelineFn
Pipe applied to create a usefulpipeline
function type
Other types exported
ExtractFunctionArguments
extracts function argumentsExtractFunctionReturnValue
extracts a functions return type
Ad-hoc types that may aid in constructing applications from these types.
AnyFunction
a type representing any kind of function, an alternative to FunctionAnyFunction1
a 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[]) => string
Read more at https://dev.to/babak/introducing-the-recursive-pipe-and-compose-types-3g9o