microsoft / microsoft/TypeScript
Duplicate function declarations in generated `.d.ts` for non-module JS files with `allowJs` + `declaration`
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
### 🔎 Search Terms
allowJs declaration duplicate, allowJs declaration emit multiple files global function, declaration emit global scope merged symbol resolveAnonymousTypeMembers, script file declaration emit duplicates
### 🕗 Version & Regression Information
This is the behavior in every version I tried, including 6.0.3 (also tested typescript@next)
Playground Link: requires multi-file setup with tsconfig.json.
I used stackblitz instead.
### ⏯ Playground Link
https://stackblitz.com/edit/node-emxsybj1?file=tsconfig.json
### 💻 Code
**tsconfig.json**
```json
{
"compilerOptions": {
"allowJs": true,
"declaration": true,
"emitDeclarationOnly": true
},
"include": ["*.js"]
}
```
**a.js**
```js
/** @filename: a.js */
function func(x) {
return x + 1;
}
```
**b.js**
```js
/** @filename: b.js */
function func(x) {
return x + 2;
}
```
### 🙁 Actual behavior
**a.d.ts** and **b.d.ts** each contain the function declaration twice (once from each file).
**a.d.ts**
```ts
/** @filename: a.js */
declare function func(x: any): any;
declare function func(x: any): any;
```
**b.d.ts**
```ts
declare function func(x: any): any;
/** @filename: b.js */
declare function func(x: any): any;
```
### 🙂 Expected behavior
Each **.d.ts** should only contain the declaration from its own source file or error (not sure).
### Additional information about the issue
related issues:
- #27011
- #49200
**EDIT1:** updated _Expected behavior_
コントリビューションガイド
調査の方向性
まず、報告されている tsconfig.json と2ファイルの a.js/b.js の再現ケースで tsc を実行し、次にグローバルシンボルの宣言出力と、検索語で言及されている resolveAnonymousTypeMembers のパスを追跡します。出力を issue #27011 および #49200 と比較します。完了条件は、生成された各 .d.ts にそれ自身の宣言だけが含まれること、またはその動作が無効な場合にコンパイラが明確なエラーを報告することです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 48/100