microsoft / microsoft/TypeScript

unique symbol lost on assignment to const despite type assertion

オープン
#55,901 コメント 7 件 リアクション 4 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

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

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:

@Andarist perhaps https://github.com/microsoft/TypeScript/pull/54778 also fixes this?

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

リンクされている TypeScript Playground から始め、unique-symbol アサーションで推論される型を、対応する文字列リテラルおよび数値リテラルの場合と比較します。const 宣言と型アサーションに対するコンパイラーの widening の挙動を追跡し、関連するケースをリグレッションさせずに、アサーションされた unique-symbol 型が保持されることを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
42/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。