SystemJS,Typescript,angular2和模块化

SystemJS, Typescript, angular2 and modularity

本文关键字:模块化 Typescript SystemJS angular2      更新时间:2023-09-26

我正在尝试使用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

引导程序.ts

...
import {PageCmp} from 'page-module/index';
bootstrap(PageCmp, [
  ...
]);

页面.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'.

我怎样才能告诉打字稿编译器这个模块?或者我可以通过其他方式或模块系统来实现此模块的使用吗?
我也可以在没有直接"/index"引用的情况下以某种方式实现这种用法import {PageCmp} from 'page-module'

附言这是我在本次讨论中的最后一个问题的复制粘贴

这个问题完全是关于我的问题。等待使用moduleResolution: 'target'的打字稿更新

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