microsoft / microsoft/TypeScript
Assign a known symbol to a constant should retain type information
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
Suggestion
Assigning a known symbol constant to another constant should retain type information.
const foo = Symbol() // known symbol
const bar = foo // expecting 'typeof foo' but received 'symbol'
interface UseFoo {
[foo]: 'value'
}
// This should work
const useBar: UseFoo = {
[bar]: 'value'
}
Use Cases
Creating aliases of symbol constants without losing type information.
Examples
Symbol.iterator alias
const { iterator } = Symbol
const iterable: Iterable<number> = {
* [iterator] () {
yield * [0, 1, 2, 3]
}
}
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript / JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. new expression-level syntax)
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 damit, das Symbolalias-Beispiel foo/bar und das Destrukturierungsbeispiel mit Symbol.iterator in TypeScript zu reproduzieren. Verfolge, wie der Compiler die Typen dieser Aliase ableitet und wie berechnete Eigenschaftsschlüssel geprüft werden; abgeschlossen ist die Aufgabe, wenn beide Beispiele den bekannten Symboltyp beibehalten, ohne das erzeugte JavaScript zu ändern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 35/100