microsoft / microsoft/TypeScript
unique symbol lost on assignment to const despite type assertion
オープン
まだ誰も着手していません。
In Discussion
Suggestion
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
🔎 Search Terms
unique symbol widening
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
const u = Symbol();
const a7 = u as typeof u // widened to symbol
🙁 Actual behavior
a7 is symbol
🙂 Expected behavior
a7 has typeof u
Additional information about the issue
This issue is a huge problem for isolated declarations as it breaks the assumption that in an expression const o = a as T we can always use T as the type of o. This is also inconsistent with the way similar expressions work for string/number literal types (ex)
Similar issues:
- https://github.com/microsoft/TypeScript/issues/43657 - Widening on return type not on variable declaration
- https://github.com/microsoft/TypeScript/issues/55361 - Similar, explicitly typed variable is widened
- https://github.com/microsoft/TypeScript/issues/36876 - Widening when assigning from object property (but no assertion)
- https://github.com/microsoft/TypeScript/issues/53276
@Andarist perhaps https://github.com/microsoft/TypeScript/pull/54778 also fixes this?
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされている TypeScript Playground から始め、unique-symbol アサーションで推論される型を、対応する文字列リテラルおよび数値リテラルの場合と比較します。const 宣言と型アサーションに対するコンパイラーの widening の挙動を追跡し、関連するケースをリグレッションさせずに、アサーションされた unique-symbol 型が保持されることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100