microsoft / microsoft/TypeScript

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

Open
#63,837 0 comments 1 reaction 2 assignees View on GitHub

@jakebailey is already working on this.

Since Jun 16, 2026.

Possible Improvement
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

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
```

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.