microsoft / microsoft/TypeScript
[Feature request] sort literals in .d.ts
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Search Terms
Suggestion
sort string literal in .d.ts
Use Cases
avoid string literal random change order when source code didn't change
and make code history is more easy read
in this issue thread string literal is mean => "a" | "c" | "b"
this not only happen on Record, it has chance happen at all type is auto create by typescript emit with string literal
Examples
"a" | "c" | "b"is create by typesctipt emit and some time will random change order
- https://github.com/bluelovers/cjk-convert/blob/1a0ba9f85e0bf7fe916158cc14a4ef87507106d9/lib/zh/table/table.ts#L1619-L1635
- https://github.com/microsoft/TypeScript/issues/30328
- https://github.com/bluelovers/novel-travis-test/commit/3b88745e187736797d9a30d4f4bbd927b0c6dd30#diff-3006c96d8657ccca5b9b3618a256314c
- https://github.com/bluelovers/novel-travis-test/commit/d33c4a61602a8536d1414d36e027eb99845104f1#diff-3006c96d8657ccca5b9b3618a256314c
- https://github.com/bluelovers/novel-travis-test/commit/2d749195c39ef386e6c4bad1ae6e19d007c03e93#diff-3006c96d8657ccca5b9b3618a256314c
current .d.ts output
export declare const table_plus: Record<"a" | "c" | "b">
// "a" | "c" | "b" is random change order
in this request
sort ( use simple array.sort() ) it when output emit at
.d.ts
export declare const table_plus: Record<"a" | "b" | "c">
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.
Maintainer's note [@sandersn]: To implementers: When you implement this, be sure to sort other literal types too. Consider sorting other things, like symbol, by the order of their string representation.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
.d.ts の例に対する TypeScript の宣言出力パスを、特に Record 型の string-literal union がどのように生成されるかに注目して、まず追跡します。出力された結果を要求されたソート順と比較し、その後、他のリテラル型とシンボルについてのメンテナーの注記を検討します。実行時の JavaScript の動作を変更せずに宣言出力が決定論的になれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100