microsoft / microsoft/TypeScript

Missing compiler error (or emit bug) in another isolatedModules + emitDecoratorMetadata use case

Abierto
#61,411 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Awaiting More Feedback Suggestion
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
2 d 4 h
PR fusionados (30 d)
132

Descripción

🔎 Search Terms

"isolatedModules" "emitDecoratorMetadata"

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ
⏯ Playground Link

https://www.typescriptlang.org/dev/bug-workbench/?importHelpers=true&experimentalDecorators=true&emitDecoratorMetadata=true&target=99&module=1&isolatedModules=true&noResolve=true&lib=lib.esnext.d.ts%2Clib.decorators.legacy.d.ts&ts=5.3.2#code/PTAEAEEsGcHsBsCGAXApgEwLK3QV3qtAFAgSoAeADqgE6QC2qAdsovACKoDGsNKvxUuFY0A5qmQAuUAFEAygDkKyEmHAVqdRizacefZAOnIauVKrL1IyPb341MExOhSJjp80PiQARtMJMygA06Nx2hjTQAHQEoohcAJ4W4ABmkARMiIzGCdQAtBq8yFHIxIU0yKDIuaigAIKgALygACwA3ETJaRlZqNK40Kh5ofr2eQDu1gAWedXUJcQMlEWgAN5VNfWgAL6gKTSw9KAARFHAc0PlxQBW0McdRFd7uExcyJCwTKAAKoTIABQASjWRFAoBoElwNC+L1CaUC6FAiGgSKYCSRKIACog+Iw0DRbAZeB1tp0nlwkNAUQANEFgnhMaAmXBvXj-cC-JlA0DkaR1YGrUnbIA

💻 Code
// @isolatedModules
// @experimentalDecorators
// @target: ESNext
// @experimentalDecorators: true
// @emitDecoratorMetadata: true
// @lib: esnext,decorators.legacy
// @filename: type-export.ts
export type A = 4;

// @filename: use-decorator-with-type.ts
import { type A } from "./type-export.js";

export function Test() {
  return undefined as any as ParameterDecorator;
}

export class X {
  constructor(@Test() x: A) {}
}
🙁 Actual behavior

The key issue here is that the emitted file for use-decorator-with-type.ts looks like this:

/* ... helpers snipped ... */
export function Test() {
    return undefined;
}
let X = class X {
    constructor(x) { }
};
X = __decorate([
    __param(0, Test()),
    __metadata("design:paramtypes", [Number])
], X);
export { X };

And the problematic line is __metadata("design:paramtypes", [Number]).

Typescript manages to avoid any broken imports and produce working runtime code but the runtime code leaks information about the type of A from the other file by using Number in the metadata. This seems like a clear violation of isolatedModules, but no compiler error is emitted.

🙂 Expected behavior

TS should either emit an isolatedModules-related error or should output something more generic than Number. If the emit is changed, though, I'm not sure what the ecosystem ramifications would be, so probably this should just be an error.

Additional information about the issue

No response

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comience con la reproducción proporcionada en Playground usando type-export.ts y use-decorator-with-type.ts, y luego inspeccione la ruta del compilador responsable de isolatedModules y emitDecoratorMetadata. Reproduzca la salida emitida __metadata("design:paramtypes", [Number]) y determine si el fix completado debería informar un diagnóstico de isolatedModules o cambiar los metadatos emitidos, con cobertura de regresión para este caso.

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
32/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.