microsoft / microsoft/TypeScript

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

Offen
#63,837 0 Kommentare 1 Reaktion 2 zugewiesene Personen Auf GitHub ansehen

@jakebailey arbeitet bereits daran.

Seit 16.6.2026.

Possible Improvement
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

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.
/** ========> 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

/** ========> 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

/** ========> 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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.