javascript - SystemJS、Typescript、Angular2 和模块化

标签 javascript typescript angular systemjs

我正在尝试使用 angular2/systemjs/typescript 编写基本应用程序,并使用我与 angular1 一起使用的模块化功能,但遇到了一些问题。
我在应用程序中的任何位置都需要这个东西,而不依赖于文件的相对位置,其中 smth-module 是我编写并包含(导出)SmthCmp 类的任何模块

import SmthCmp from 'smth-module';

测试应用结构

├── bootstrap.ts
├── graph-module
│   ├── component
│   │   └── line-graph
│   │       └── line-graph.ts
│   └── index.ts
└── page-module
    ├── component
    │   └── page
    │       └── page.ts
    └── index.ts

bootstrap.ts

...
import {PageCmp} from 'page-module/index';

bootstrap(PageCmp, [
  ...
]);

page.ts

...
import {LineGraphCmp} from 'graph-module/index';

...
export class PageCmp {}

折线图.ts

...
export class LineGraphCmp {}

图形和页面模块索引像这样

export {PageCmp} from './component/page/page';

还添加到System.config()

map: {
    'graph-module': '/graph-module',
    'page-module': '/page-module'
}

所以我可以在任何地方使用 export Smth from 'module/index' 语法,这几乎就是我所需要的。但有一个问题

app/bootstrap.ts(4,23): error TS2307: Cannot find module 'page-module/index'.
app/page-module/component/page/page.ts(8,28): error TS2307: Cannot find module 'graph-module/index'.

我如何告诉 Typescript 编译器有关此模块的信息?或者我可以通过其他方式或模块系统实现此模块的使用吗?
另外,我可以以某种方式实现此用法 import {PageCmp} from 'page-module' 而不直接引用 '/index' 吗?

附:这是我上一个问题的复制粘贴:this discussion

最佳答案

这个问题完全是关于我的问题。等待 Typescript 更新 moduleResolution: 'target' 用法

https://github.com/Microsoft/TypeScript/issues/5039

关于javascript - SystemJS、Typescript、Angular2 和模块化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34862013/

相关文章:

javascript - ajax后在php中获取输入复选框值

javascript - 五个圆圈对齐,当我点击圆圈时,我希望数字 5 出现在圆圈内

javascript - AngularJS 表单自定义验证( future 日期)

javascript - useRef 当前仅在第二次更新时获取其值

angular - 如何删除 Angular 中给定名称的标题?

reactjs - 如何重用 react-router 的 useHistory 的 Jest 模拟

javascript - 如何从不同的组件调用其他组件功能?

javascript - 访问 Angular 2 应用程序的路由时如何在 URL 中保留查询字符串参数?

javascript - jQuery 追加 onclick

angularjs - Angular 2 - 子组件如何与父组件对话?