microsoft / microsoft/TypeScript
allowJs option with namespaces
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
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'."
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
先使用 TypeScript 1.8.10 从两个示例文件和提供的 tsconfig.json 开始,然后通过 allowJs、namespaces 和 outFile 重现 TS2300 重复标识符错误。完成的标准是:无需修改 JavaScript 或报告重复标识符,即可将 TypeScript 和 JavaScript 的 namespace 代码打包到一个 JavaScript 文件中。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100