microsoft / microsoft/TypeScript
Duplicate function declarations in generated `.d.ts` for non-module JS files with `allowJs` + `declaration`
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.3k
- Merge trung bình
- 2 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 132
Mô tả
### 🔎 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_
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách chạy tsc với tsconfig.json được báo cáo và bản tái hiện gồm hai tệp a.js/b.js, sau đó truy vết quá trình phát sinh khai báo cho các symbol toàn cục và đường dẫn resolveAnonymousTypeMembers được đề cập trong các từ khóa tìm kiếm. So sánh đầu ra với các issue #27011 và #49200. Được xem là hoàn tất khi mỗi .d.ts được tạo ra chỉ chứa khai báo của chính nó, hoặc trình biên dịch báo cáo một lỗi rõ ràng nếu hành vi đó không hợp lệ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, typescript
- Lĩnh vực
- compilers
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 48/100