microsoft / microsoft/TypeScript
Pipe/flow/chain type support
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
Search Terms
recursive, flow, pipe, chain
Suggestion
I do not have a specific implementation in mind to support this. There is a decent existing solution by a stackoverflow user @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 is integrated into javascript?
Use Cases
There are a number of implementations for javascript pipes in common libraries.
Related Issues
https://github.com/Microsoft/TypeScript/issues/27102
https://github.com/Microsoft/TypeScript/issues/28505
Examples
a typical implementation looks like this:
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
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず pipe の例、リンクされている lodash、RxJS、Ramda の実装、および関連する issue 27102 と 28505 を確認してください。完了条件は、再帰的な型推論の合意済み設計、または公式の Chain type を確立することであり、再帰とパイプライン演算子に関する未解決の疑問も含まれます。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 25/100