microsoft / microsoft/TypeScript
Support implicit invocations of `Symbol.toPrimitive` for statically-named properties
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
Bug Report
Original Title: Type declaration merging of a class, a namespace and another type like symbol or string
Given the following declaration
const ASymbol = Symbol('A');
class A {
static [Symbol.toPrimitive]() {
return ASymbol;
}
}
namespace A {
export type T = any;
}
I get an error when I do this:
class TestClass {
[A]() { // error
}
}
The why doesn't matter. It's a bug because Typescript is a "superset" of Javascript and it works in the latter.
It can be worked around with hacks like
const AWrapper: typeof A & typeof ASymbol = A as any;
class TestClass2 {
[AWrapper]() { // works
}
otherMethod() {
this[AWrapper](); // although this still gives an error
}
}
But then I'm not able to do this:
let o: AWrapper.T; // error
It loses the the namespace properties.
Is it possible to merge all type declarations so that at least the hack can be used?
🔎 Search Terms
declaration merging class namespace type symbol string intersection
🕗 Version & Regression Information
Playground Latest v5+
⏯ Playground Link
💻 Code
In the description
🙁 Actual behavior
Error
🙂 Expected behavior
No error, or at least a way to hack around.
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 verknüpften TypeScript Playground-Reproduktion und vergleiche den gemeldeten Fehler bei der berechneten Eigenschaft mit dem entsprechenden JavaScript-Verhalten. Verfolge, wie der Compiler die statisch benannte Eigenschaft und das Zusammenführen von Deklarationen prüft; abgeschlossen ist die Arbeit, wenn das Beispiel ohne den Fehler kompiliert wird und der zusammengeführte Namespace-Typ weiterhin verwendbar ist.
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
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100