microsoft / microsoft/TypeScript
allowJs option with namespaces
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.4k
- Merge trung bình
- 1 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 117
Mô tả
I am currently trying to put the compiler option "allowJs" to use. My goal is to convert an existing JavaScript application into TypeScript step by step. The application does not use (external) modules, so I'm converting the JavaScript namespaces into real TypeScript namespaces, but I'm running into "duplicate identifier" errors as outlined below. Shouldn't it be possible to combine TypeScript and JavaScript using the same namespace? Maybe I'm doing something wrong or this is not intended, but I expected this to work.
TypeScript Version: 1.8.10
Code
File 1:
namespace myapp {
export var c1 = 5;
}
File 2:
var myapp;
(function (myapp) {
myapp.c2 = 4;
})(myapp || (myapp = {}));
tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"outFile": "dist/appBundle.js"
}
}
Expected behavior:
Bundling the compiled code of file 1 and the code of file 2 without modifications into a single JavaScript file.
Actual behavior:
The compilation is done, but the compiler throws an error: "error TS2300: Duplicate identifier 'myapp'."
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 với hai tệp ví dụ và tsconfig.json được cung cấp bằng TypeScript 1.8.10, sau đó tái hiện lỗi TS2300 do mã định danh trùng lặp với allowJs, namespaces và outFile. Hoàn thành có nghĩa là mã namespace của TypeScript và JavaScript có thể được gói vào một tệp JavaScript duy nhất mà không sửa đổi JavaScript hoặc báo cáo mã định danh trùng lặp.
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
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 45/100