microsoft / microsoft/TypeScript
unique symbol lost on assignment to const despite type assertion
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
🔎 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?
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem verlinkten TypeScript Playground und vergleiche die abgeleiteten Typen für die unique-symbol-Assertion mit den entsprechenden Fällen für String- und Zahlenliterale. Verfolge das Widening-Verhalten des Compilers für const-Deklarationen und Typassertionen und überprüfe anschließend, dass der behauptete unique-symbol-Typ erhalten bleibt, ohne die verwandten Fälle zu regressieren.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 42/100