microsoft / microsoft/TypeScript
Tuple iteration and merging
オープン
まだ誰も着手していません。
In Discussion
Suggestion
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
Edit: Remove indexing part
Edit 2: Replace tuple mapping syntax with normal mapped types
Search Terms
Concatentate and merge tuples' entries.
Suggestion
- I would like to be able to extract and spread in positions other than the last part of a tuple.
- I would like to merge a tuple into an intersection or concatenation of its members.
Use Cases
- Converting a tuple to its intersection, such as with
Object.assign's assignee. - Typing
Array.prototype.concatcorrectly for tuples.
Syntax
The syntax comes in a few new forms:
[...A, B]appendsBto the tupleA. Similarly,[...infer A, any] extends B ? A : []drops the last item of the tuple and[...any[], infer A] extends B ? A : neverextracts the first.{... ...T}for an n-ary merge and[... ...T]an n-ary concatenation.
Examples
Here's the types for each method I mentioned above.
interface Array<T> {
concat<U extends any[]>(...others: U): [...this, ... ...{[I in keyof U]: (
U[I] extends any[] ? N : U[I] extends ArrayLike<infer R> ? R[] : [U[I]]
)}];
}
interface ObjectConstructor {
assign(target: {... ...typeof sources}, ...sources: object[]): typeof target;
}
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. new expression-level syntax)
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
この issue では、TypeScript の型システムにおけるタプルのスプレッド、タプルの連結、およびタプルから交差型へのマージが提案されており、Array.concat と Object.assign の例が示されています。実装ファイル、テスト、エントリポイントは指定されていません。まず関連する型システムの領域を特定し、その後、提案されたタプルの動作と例が機能することを示すテストを用意してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 20/100