microsoft / microsoft/TypeScript
Convert named tuple into object literal type.
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Search Terms
refactor
Suggestion
Provide a refactor that convert named tuple into object literal type.
Use Cases
Now we have named tuple.
It's common to write a tuple to pass multiple value.
As time goes on, you may add many other fields into tuple.
You cannot take a subsequence in the middle or the end of the tuple.
If we could convert that into an object, That would be useful.
Examples
type Tuple = [number, number]
function aggregate(items: number[]): Tuple {
// ...
return [min, max]
}
const [ min, max ] = aggregate(items)
Growth to
type Tuple = [number, number, number, number, number, number]
function aggregate(items: number[]): Tuple {
// ...
return [min, max, avg, mid, first, last]
}
const [ min, max, avg, mid, first, last ] = aggregate(items)
If we want first and last only
const [ , , , , first, last ] = aggregate(items) // too many '.'
const result = aggregate(items);
const first = result[4] // magic number
const last = result[5] // magic number
If we have the refactor
// add names into tuple
type Tuple = [min: number, max: number, avg: number, mid: number, first: number, last: number]
// apply refactor
type Tuple = {min: number, max: number, avg: number, mid: number, first: number, last: number}
function aggregate(items: number[]): Tuple {
// ...
return {min, max, avg, mid, first, last}
}
const { first, last } = aggregate(items)
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 番号を参照したプルリクエストを送ります。
調査の方向性
まず TypeScript language-service のリファクタリング基盤と既存のリファクタリングテストを確認し、次にこの issue の named tuple の例とそれらの規約を比較します。リファクタリングによって named tuple 型を同等の object literal 型に変換でき、説明されているプロパティベースの使用方法をサポートし、その変換を対象とするテストがあることが完了条件です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- developer-experience
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 32/100