microsoft / microsoft/TypeScript

Behavior difference: Block comments on `@typedef` structural types are not preserved, if they are imported and reconstructed as inline types in another file

Offen
#63,839 5 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

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

Beschreibung

A follow-up on https://github.com/microsoft/typescript-go/issues/4235.

---

## Steps to reproduce

1. Start a plain new project
- "@typescript/native-preview": "7.0.0-dev.20260617.2",
- "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,
3. Add the below files. Run `npx tsc` & `npx tsgo` to see the difference.

```ts
/** ========> src/lib.js <======== */
/**
* @typedef {Object} Foo
* @property {boolean} bool Whether `.bool` is true or not
*/
export class C {
/** @returns {Foo} */
getFoo() { return { bool: false }; }

/**
* @typedef {Object} Bar
* @property {boolean} bool Whether `.bool` is true or not
*/
/** @returns {Bar} */
getBar() { return { bool: false }; }
}

/** ========> src/mainJs.js <======== */
import { C } from './lib.js';

export class MainJs {
constructor() {
this.c = new C();
};

getFoo() { return { ...this.c.getFoo() }; }
getBar() { return { ...this.c.getBar() }; }
}

/** ========> src/mainTs.ts <======== */
import { C } from './lib.js';

export class MainTs {
constructor(public c: C) {};

getFoo() { return { ...this.c.getFoo() }; }
getBar() { return { ...this.c.getBar() }; }
}
```

## Behavior with `typescript@6.0`

```ts
/** ========> dist/mainJs.d.ts <======== */
export class MainJs {
c: C;
getFoo(): {
/**
* Whether `.bool` is true or not
*/
bool: boolean;
};
getBar(): {
/**
* Whether `.bool` is true or not
*/
bool: boolean;
};
}
import { C } from './lib.js';

/** ========> dist/mainTs.d.ts <======== */
import { C } from './lib.js';
export declare class MainTs {
c: C;
constructor(c: C);
getFoo(): {
/**
* Whether `.bool` is true or not
*/
bool: boolean;
};
getBar(): {
/**
* Whether `.bool` is true or not
*/
bool: boolean;
};
}
```

## Behavior with `tsgo`

```ts
/** ========> dist/mainJs.d.ts <======== */
import { C } from './lib.js';
export declare class MainJs {
c: C;
constructor();
getFoo(): {
bool: boolean;
};
getBar(): {
bool: boolean;
};
}

/** ========> dist/mainTs.d.ts <======== */
import { C } from './lib.js';
export declare class MainTs {
c: C;
constructor(c: C);
getFoo(): {
bool: boolean;
};
getBar(): {
bool: boolean;
};
}
```

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.

Rechercherichtung

Reproduziere den Unterschied mit src/lib.js, src/mainJs.js und src/mainTs.ts bei aktiviertem allowJs, checkJs und stableTypeOrdering und führe anschließend npx tsc und npx tsgo aus. Vergleiche die erzeugten Dateien dist/mainJs.d.ts und dist/mainTs.d.ts; die Korrektur ist vollständig, wenn rekonstruierte Inline-Typen die @property-Kommentare in beiden Ausgaben bewahren.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
go, javascript, typescript
Bereich
compilers
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

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