microsoft / microsoft/TypeScript
error TS4058: Return type of exported function has or is using name '$SYM' from external module fileA but cannot be named
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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).
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con il repro a due file in fileA.ts e fileB.ts, usando declaration=true e le versioni di TypeScript descritte nel report. Traccia la generazione della dichiarazione per il tipo restituito di func esportata e per il simbolo importato. Il lavoro è completato quando il repro viene compilato ed emette dichiarazioni che preservano correttamente il riferimento al simbolo senza TS4058.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100