ITADN

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

#63546OpenLangLangBart 创建于 2026-06-10
Fixed
L
LangLangBartcommented
### 🔎 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_
2 条评论