microsoft / microsoft/TypeScript
Symbols in const assertions should be considered unique
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
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: —
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 der aktualisierten TypeScript Playground-Reproduktion und bestätige den TS1166-Fehler für sealedDictionary.prop in der berechneten Klasseneigenschaft. Verfolge den Typprüfpfad für const assertions und unique symbol-Eigenschaftsnamen und füge anschließend eine Abdeckung hinzu, die zeigt, dass der sealedDictionary-Fall akzeptiert wird, ohne den abgelehnten dictionary-Fall zu ändern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100