microsoft / microsoft/TypeScript

Behavior difference: Type emit inconsistency with dangling block comment in file

Aperta
#63,837 0 commenti 1 reazione 2 assegnatari Vedi su GitHub

@jakebailey ci sta già lavorando.

Dal 16/6/2026.

Possible Improvement
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

Summary as below. I call this situation _dangling block comment_, since there are more than just newlines in between the block comments and the attached variables in the code.

Note that a fix for `top, .ts` will be a breaking change from TS 6.

| | tsc | tsgo |
|-------------|---------------------------------------------------|---------------------------------------------------|
| nonTop, .js | ✅ Dangling comment erased | ✅ Dangling comment erased |
| nonTop, .ts | ✅ Dangling comment erased | ✅ Dangling comment erased |
| top, .js | ✅ Dangling comment erased | ❌ Dangling comment attached to incorrect variable |
| top, .ts | ❌ Dangling comment attached to incorrect variable | ❌ Dangling comment attached to incorrect variable |

---

## Steps to reproduce

1. Start a plain new project
- "@typescript/native-preview": "7.0.0-dev.20260612.1",
- "typescript": "6.0.3"
2. Run `npx tsgo --init` to get the default tsconfig. Turn on these flags as well.
- "allowJs": true,
- "checkJs": true,
- "stableTypeOrdering": true,
- "removeComments": false,
3. Add the below files. Run `npx tsc` & `npx tsgo` to see the difference.

```ts
/** ========> src/nonTopComment-js.js <======== */
export const e = 3;

/** Comment on nothing */

/** Comment on noop */
(function noop() {})();

export const pi = 3;

/** ========> src/nonTopComment-ts.ts <======== */
export const e = 3;

/** Comment on nothing */

/** Comment on noop */
(function noop() {})();

export const pi = 3;

/** ========> src/topComment-js.js <======== */
/** Comment on nothing */

/** Comment on noop */
(function noop() {})();

export const pi = 3;

/** ========> src/topComment-ts.ts <======== */
/** Comment on nothing */

/** Comment on noop */
(function noop() {})();

export const pi = 3;

```

## Behavior with `typescript@6.0`

```ts
/** ========> dist/nonTopComment-js.d.ts <======== */
export const e: 3;
export const pi: 3;
//# sourceMappingURL=nonTopComment-js.d.ts.map

/** ========> dist/nonTopComment-ts.d.ts <======== */
export declare const e = 3;
export declare const pi = 3;
//# sourceMappingURL=nonTopComment-ts.d.ts.map

/** ========> dist/topComment-js.d.ts <======== */
export const pi: 3;
//# sourceMappingURL=topComment-js.d.ts.map

/** ========> dist/topComment-ts.d.ts <======== */
/** Comment on nothing */
export declare const pi = 3;
//# sourceMappingURL=topComment-ts.d.ts.map
```

## Behavior with `tsgo`

```ts
/** ========> dist/nonTopComment-js.d.ts <======== */
export declare const e = 3;
export declare const pi = 3;
//# sourceMappingURL=nonTopComment-js.d.ts.map

/** ========> dist/nonTopComment-ts.d.ts <======== */
export declare const e = 3;
export declare const pi = 3;
//# sourceMappingURL=nonTopComment-ts.d.ts.map

/** ========> dist/topComment-js.d.ts <======== */
/** Comment on nothing */
export declare const pi = 3;
//# sourceMappingURL=topComment-js.d.ts.map

/** ========> dist/topComment-ts.d.ts <======== */
/** Comment on nothing */
export declare const pi = 3;
//# sourceMappingURL=topComment-ts.d.ts.map
```

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.