【发布时间】:2016-01-28 15:45:06
【问题描述】:
我想在我的 TypeScript(with Angular 2)应用程序中创建本地 模块,然后简单地引用任何带有导入模块的文件,例如 myApp/components、myApp/pipes等等,而不是像我现在必须做的那样使用相对路径 (../../../MyComponent)。
例如,Angular 2 可以这样使用。 (我还没找到他们是怎么做到的)
import {Component} from 'angular2/core';
我怎样才能实现这种行为?
我做了一些文件,如components.ts、templates.ts 等,我从当前部分导出文件:
export * from './menu/item';
export * from './menu/logo';
export * from './article/article';
export * from './article/sidebar';
...然后我有一个主文件myApp.ts,我在其中声明了这样的模块:
declare module 'myapp/components' {
export * from './application/components';
}
declare module 'myapp/templates' {
export * from './application/templates';
}
但是这个文件没有生成任何东西,所以 TS build 告诉我像...file_path...(4,9): error TS2305: Module ''myapp/components'' has no exported member 'AlfaBeta'.
这样的错误
顺便说一句。我的tsconfig.json 看起来像这样:
{
"compilerOptions": {
"target": "ES5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules"
]
}
【问题讨论】:
标签: typescript angular