microsoft / microsoft/TypeScript
Re-export module namespace as global
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
We're attempting to migrate users within Google to new @types typings, which move most typings into modules, and having a ton of trouble. The basic problem is that a module (e.g. CodeMirror) used to declare a global complex interface:
declare function CodeMirror(...);
declare namespace CodeMirror { ... }
and now they are modules:
export = CodeMirror;
and other typings refer to them as modules (so we can't just undo that export statement) but we also have tons of older user code that doesn't refer to them as modules. Ideally we'd be able to make it work both ways while we migrate users incrementally.
I appreciate that you don't want the language to make this convenient, but I'm having difficulty finding any way to make it work temporarily while we migrate.
Some things I tried:
- Aliasing the module into the global namespace
declare global {
import CodeMirror = require('codemirror');
}
(and other variants) fails with "Imports are not permitted in module augmentations.".
- Making the module global first, then aliasing it into a module namespace.
If you wrap the file contents with a "declare global {", then I couldn't figure out a way to repackage that global as a module again. Theexport = CodeMirror;fails with "Cannot find name 'CodeMirror'." despite the global CodeMirror being declared in the same file.
Do you have any advice? Note that "export as namespace" doesn't help because our user code is already modules, not scripts.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 issue 中引用的两种声明模式和诊断信息开始。跟踪 export =、declare global 和 export as namespace 的处理方式,然后确定受支持的方法或语言变更是否能够同时满足模块用法和全局用法;只有在有明确且经过测试的解决方案时,才能算完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, typescript
- 领域
- compilers
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100