microsoft / microsoft/TypeScript

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

Open
#61,411 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

### 🔎 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

```ts repro
// @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:

```ts
/* ... 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_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided Playground reproduction using type-export.ts and use-decorator-with-type.ts, then inspect the compiler path responsible for isolatedModules and emitDecoratorMetadata. Reproduce the emitted __metadata("design:paramtypes", [Number]) output and determine whether the completed fix should report an isolatedModules diagnostic or change the emitted metadata, with regression coverage for this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.