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

オープン
#63,839 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る
Possible Improvement
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

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

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

allowJs、checkJs、stableTypeOrderingを有効にした状態でsrc/lib.js、src/mainJs.js、src/mainTs.tsを使用して差異を再現し、その後npx tscとnpx tsgoを実行します。生成されたdist/mainJs.d.tsとdist/mainTs.d.tsのファイルを比較します。再構築されたインライン型が両方の出力で@propertyコメントを保持すれば、修正は完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
go, javascript, typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。