microsoft / microsoft/TypeScript
error TS4058: Return type of exported function has or is using name '$SYM' from external module fileA but cannot be named
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
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).
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con la reproducción de dos archivos en fileA.ts y fileB.ts, usando declaration=true y las versiones de TypeScript descritas en el informe. Sigue la generación de declaraciones para el tipo de retorno de func exportada y el símbolo importado. Se considera terminado cuando la reproducción compila y emite declaraciones que preservan correctamente la referencia al símbolo sin TS4058.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- compilers
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100