Repository: TypeScript
Issue: Pipe/flow/chain type support
Labels: Suggestion,Needs Proposal

<!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨

Half of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Please read the FAQ first, especially the "Common Feature Requests" section.

-->

## Search Terms
recursive, flow, pipe, chain
<!-- List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily -->

## Suggestion
I do not have a specific implementation in mind to support this. There is a decent existing solution [by a stackoverflow user](https://stackoverflow.com/questions/53173203/typescript-recursive-function-composition) @jcalz, which does its best given what typescript is able to accomplish now. I have created this issue to more to specifically point out the current limitation of typescript in regard to this feature, and the current use cases. This feature request falls under the larger umbrella of recursive type inference.

At its most broad, I would like to suggest that typescript include some form of an official `Chain` type that developers can use.

## Unanswered Questions
- should this type have an official implementation with a max recursion value? `pipe: Chain<In, Out, number>`
- will this design pattern cease to be relevant if the [tc39 pipeline proposal](https://github.com/tc39/proposal-pipeline-operator) is integrated into javascript?

<!-- A summary of what you'd like to see added or changed -->

## Use Cases
There are a number of implementations for javascript pipes in common libraries.
- [lodash pipe](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/lodash/fp.d.ts#L309)
- [rxjs pipe](https://github.com/ReactiveX/rxjs/blob/master/src/internal/util/pipe.ts#L5)
- [ramda pipe](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/ramda/index.d.ts#L1941)

## Related Issues
https://github.com/Microsoft/TypeScript/issues/27102
https://github.com/Microsoft/TypeScript/issues/28505
<!--
What do you want to use this for?
What shortcomings exist with current approaches?
-->

## Examples
a typical implementation looks like this:
```ts
function pipe<T, A>(arg1: (in: T) => A): A
function pipe<T, A, B>(arg1: (in: T) => A, arg2: (in: A) => B): (in: T) => B
function pipe(...args: any[]): (in: any) => any


const strToNumber = (str: string) => parseInt(str)
const add = (x: number) => (y: number) => x + y
const safeAdder = pipe(strToNumber, add(5))
const out: number = safeAdder('6') // returns 11
```
The limitation of the current implementation is that if you use a typed pipe function with more arguments than the written overloads, you run lose type inference.

## Checklist

My suggestion meets these guidelines:

* [ ] This wouldn't be a breaking change in existing TypeScript/JavaScript code
* [ ] This wouldn't change the runtime behavior of existing JavaScript code
* [X] This could be implemented without emitting different JS based on the types of the expressions
* [X] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
* [X] This feature would agree with the rest of [TypeScript's Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals).