microsoft / microsoft/TypeScript
error TS4058: Return type of exported function has or is using name '$SYM' from external module fileA but cannot be named
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
🔎 Search Terms
cannot be named symbol
TS4058
🕗 Version & Regression Information
- This changed between versions 4.7.4 and 5.2.0-dev.20230710
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about "cannot be named"
⏯ Playground Link
Two files involved, so can't make a playground link
💻 Code
declaration=true
// fileA.ts
export const $SYM = Symbol("$SYM");
export const OBJ = { [$SYM]: 42 };
// fileB.ts
import type { $SYM, OBJ } from "./fileA";
export function func(obj: typeof OBJ, sym: typeof $SYM) {
return [obj, sym];
}
🙁 Actual behavior
Error: Return type of exported function has or is using name '$SYM' from external module "fileA" but cannot be named.
🙂 Expected behavior
The expectation was that it compiles. Because if I use a string constant literal instead of the symbol, it works.
P.S.
In version 4.7.4 it worked, BUT it worked incorrectly: it generated declarations like function func(obj: { [$SYM]: number }) without actually importing $SYM, so it treated $SYM as a string (I think it was a bug). Now that bug is fixed, but there is still no way to generate declarations for similar situations (and as you can see, importing $SYM explicitly doesn't help).
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 Zwei-Dateien-Repro in fileA.ts und fileB.ts, unter Verwendung von declaration=true und den im Bericht beschriebenen TypeScript-Versionen. Verfolge die Generierung der Deklaration für den Rückgabetyp von func und das importierte Symbol. Als erledigt gilt die Aufgabe, wenn das Repro kompiliert und Deklarationen erzeugt, die die Symbolreferenz ohne TS4058 korrekt beibehalten.
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