microsoft / microsoft/TypeScript
Missing compiler error (or emit bug) in another isolatedModules + emitDecoratorMetadata use case
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
🔎 Search Terms
"isolatedModules" "emitDecoratorMetadata"
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ
⏯ Playground Link
💻 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
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
Iniziare con la riproduzione fornita in Playground usando type-export.ts e use-decorator-with-type.ts, quindi esaminare il percorso del compilatore responsabile di isolatedModules ed emitDecoratorMetadata. Riprodurre l'output emesso __metadata("design:paramtypes", [Number]) e determinare se il fix completato debba segnalare una diagnostica isolatedModules o modificare i metadati emessi, con copertura di regressione per questo caso.
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
- 32/100