Skip to content

Commit

Permalink
fix: improved typings
Browse files Browse the repository at this point in the history
  • Loading branch information
GabeDuarteM committed Apr 6, 2019
1 parent a994f72 commit 84dc37a
Showing 1 changed file with 110 additions and 1 deletion.
111 changes: 110 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,113 @@
const pipe = <T>(initialValue: T, ...args: any[]): any => {
export type PipeFn<ReceivedValue, ReturnedValue> = (
value: ReceivedValue,
) => ReturnedValue

function pipe<T, V0>(initialValue: T, ...args: [PipeFn<T, V0>]): V0
function pipe<T, V0, V1>(
initialValue: T,
...args: [PipeFn<T, V0>, PipeFn<V0, V1>]
): V1
function pipe<T, V0, V1, V2>(
initialValue: T,
...args: [PipeFn<T, V0>, PipeFn<V0, V1>, PipeFn<V1, V2>]
): V2
function pipe<T, V0, V1, V2, V3>(
initialValue: T,
...args: [PipeFn<T, V0>, PipeFn<V0, V1>, PipeFn<V1, V2>, PipeFn<V2, V3>]
): V3
function pipe<T, V0, V1, V2, V3, V4>(
initialValue: T,
...args: [
PipeFn<T, V0>,
PipeFn<V0, V1>,
PipeFn<V1, V2>,
PipeFn<V2, V3>,
PipeFn<V3, V4>
]
): V4
function pipe<T, V0, V1, V2, V3, V4, V5>(
initialValue: T,
...args: [
PipeFn<T, V0>,
PipeFn<V0, V1>,
PipeFn<V1, V2>,
PipeFn<V2, V3>,
PipeFn<V3, V4>,
PipeFn<V4, V5>
]
): V5
function pipe<T, V0, V1, V2, V3, V4, V5, V6>(
initialValue: T,
...args: [
PipeFn<T, V0>,
PipeFn<V0, V1>,
PipeFn<V1, V2>,
PipeFn<V2, V3>,
PipeFn<V3, V4>,
PipeFn<V4, V5>,
PipeFn<V5, V6>
]
): V6
function pipe<T, V0, V1, V2, V3, V4, V5, V6, V7>(
initialValue: T,
...args: [
PipeFn<T, V0>,
PipeFn<V0, V1>,
PipeFn<V1, V2>,
PipeFn<V2, V3>,
PipeFn<V3, V4>,
PipeFn<V4, V5>,
PipeFn<V5, V6>,
PipeFn<V6, V7>
]
): V7
function pipe<T, V0, V1, V2, V3, V4, V5, V6, V7, V8>(
initialValue: T,
...args: [
PipeFn<T, V0>,
PipeFn<V0, V1>,
PipeFn<V1, V2>,
PipeFn<V2, V3>,
PipeFn<V3, V4>,
PipeFn<V4, V5>,
PipeFn<V5, V6>,
PipeFn<V6, V7>,
PipeFn<V7, V8>
]
): V8
function pipe<T, V0, V1, V2, V3, V4, V5, V6, V7, V8, V9>(
initialValue: T,
...args: [
PipeFn<T, V0>,
PipeFn<V0, V1>,
PipeFn<V1, V2>,
PipeFn<V2, V3>,
PipeFn<V3, V4>,
PipeFn<V4, V5>,
PipeFn<V5, V6>,
PipeFn<V6, V7>,
PipeFn<V7, V8>,
PipeFn<V8, V9>
]
): V9
function pipe<T, V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10>(
initialValue: T,
...args: [
PipeFn<T, V0>,
PipeFn<V0, V1>,
PipeFn<V1, V2>,
PipeFn<V2, V3>,
PipeFn<V3, V4>,
PipeFn<V4, V5>,
PipeFn<V5, V6>,
PipeFn<V6, V7>,
PipeFn<V7, V8>,
PipeFn<V8, V9>,
PipeFn<V9, V10>
]
): V10
function pipe<T>(initialValue: T, ...args: PipeFn<any, any>[]): any
function pipe<T>(initialValue: T, ...args: PipeFn<any, any>[]): any {
const finalValue = args.reduce((value, func) => {
const nextValue = func(value)

Expand Down

0 comments on commit 84dc37a

Please sign in to comment.