microsoft / microsoft/TypeScript
Use a consistent ordering when writing union types
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
In DefinitelyTyped, $ExpectType assertions depend on a type having a consistent string represenation across TypeScript versions.
It looks like the ordering of union types is dependent on some implementation details that change between versions. When we output unions as strings, we should sort them in some consistent way first instead of just using whatever order we happened to use internally.
I would suggest this ordering:
- numeric literals, low to high
- string literals, low to high (by
<) - named types (including type aliases, enum, class and interface names), by name
- function literals: by length (
() => voidbefore(x: number) => void), then by parameter name, then by parameter type - type literals: Sorted smallest to largest (
{ x: number }before{ x: number, y: number }); and type literals of the same size should be alphabetically sorted by property ({ a: number }) before{ b: number }) or by the sorting of values ({ s: "a" }before{ s: "b" })
Of course, another solution would be to try to handle this in $ExpectType by parsing out unions and allowing it if any sorting is valid. But it is strange in TS to see a string literal union displayed in a seemingly random order.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
ファイルもテストも指定されていません。まず、union 型を文字列に変換するコンパイラーパスを追跡し、それを DefinitelyTyped の $ExpectType アサーションと比較してください。TypeScript のバージョン間で union のメンバーが決定論的な順序に従えば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100