簡體   English   中英

SystemJS,Typescript,angular2和模塊化

[英]SystemJS, Typescript, angular2 and modularity

我正在嘗試使用與angular1一起使用的帶有模塊化的angular2 / systemjs / typescript編寫基本應用程序,並且遇到一些問題。
我不需要在文件的相對位置就可以在我的應用程序中的任何位置使用此東西,其中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 {}

線graph.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'語法中的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編譯器有關此模塊的信息? 還是可以通過其他方式或模塊系統達到此模塊的使用率?
我還能以某種方式實現這種用法而無需直接使用“ / index”引用import {PageCmp} from 'page-module'嗎?

ps這是我在本次討論中的最后一個問題的復制粘貼

這個問題完全是關於我的問題。 等待Typescript更新的moduleResolution: 'target'解析度moduleResolution: 'target'用法

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM