microsoft / microsoft/TypeScript

Duplicate function declarations in generated `.d.ts` for non-module JS files with `allowJs` + `declaration`

未关闭
#63,546 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
Bug Domain: Declaration Emit
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
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 和双文件 a.js/b.js 重现用例运行 tsc,然后跟踪全局符号的声明生成过程,以及搜索词中提到的 resolveAnonymousTypeMembers 路径。将输出与 issue #27011 和 #49200 进行比较。完成的标准是每个生成的 .d.ts 只包含其自身的声明,或者在该行为无效时由编译器报告明确的错误。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, typescript
领域
compilers
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。