microsoft / microsoft/TypeScript
Symbols in const assertions should be considered unique
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
TypeScript Version: 3.8.0-dev.20191205
Search Terms:
- const assertion unique symbol
- "unique symbol" "as const"
Code
const prop = Symbol()
const dictionary = {
prop: Symbol()
}
const sealedDictionary = {
prop: Symbol()
} as const
class MyClass {
// Works because "prop" is a unique symbol
[prop]: 1
// Does not work because "dictionary.prop" is not a unique symbol
[dictionary.prop]: 2
// Does not work because "sealedDictionary.prop" is not a unique symbol,
// even though it probably should be?
[sealedDictionary.prop]: 3
}
Expected behavior:
MyClass should probably accept sealedDictionary.prop as a computed property name since it should be considered a unique symbol.
Actual behavior:
TypeScript complains with TS1166:
A computed property name in a class property declaration must refer to an expression whose type is a literal type or a 'unique symbol' type.
Playground Link: Provided Updated (old link seems to be broken in new playground)
Related Issues: —
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
更新された TypeScript Playground の再現から始め、計算されたクラスプロパティ内の sealedDictionary.prop に対する TS1166 エラーを確認します。const assertions と unique symbol のプロパティ名に対する型チェックの経路を追跡し、sealedDictionary のケースが受け入れられ、拒否される dictionary のケースは変更されないことを示すカバレッジを追加します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100