i可以:
import * as foo from './foo'
,但似乎不能导出相同:
export * as foo from './foo'
这似乎也没有用...
import * as fooImport from './foo';
export const foo = fooImport;
有什么想法?
---更新---
您想实现什么?
基本上,我正在为我的应用程序实现ngrx/store
后端。我想这样组织我的代码:
app/core/
index.ts
viewer/
index.ts
viewer-actions.ts
viewer-reducer.ts
view-data/
index.ts
view-data-actions.ts
view-data-reducer.ts
我想使用我的index.ts
文件来链接每个子集中的所有导出(常见范式)。
但是,我想保留 namepaced 。我的xxx-reducer.ts
和xxx-actions.ts
文件中的每个文件都有相同名称的导出(reducer
,ActionTypes
,Actions
,...),因此正常的链接将导致名称碰撞。我要做的是允许xxx-actions
和xxx-reducer
中的所有导出为重新出口作为xxx
。这将使我可以:
import { viewer, viewerData } from './core';
...
private viewer: Observable<viewer.Viewer>;
private viewData: Observable<viewData.ViewData>;
ngOnInit() {
this.viewer = this.store.let(viewer.getViewer());
this.viewData = this.store.let(viewData.getViewData());
}
而不是更详细的:
import * as viewer from './core/viewer';
import * as viewerData from './core/viewer-data';
...
多数民众赞成在要点...
打字稿3.8或更高版本
请参阅https://stackoverflow.com/a/59712387/1108891有关详细信息。
打字稿3.7或更早之前
可以在打字稿中导出 *作为foo
nope。但是,您可以使用两个步骤:
src/core/index.ts
import * as Foo from "./foo";
import * as Bar from "./bar";
export {
Foo,
Bar,
}
src/index.ts
import { Foo, Bar } from "./core";
function FooBarBazBop() {
Foo.Baz;
Foo.Bop;
Bar.Baz;
Bar.Bop;
}
src/core/foo/index.ts 和 src/core/bar/index.ts
export * from "./baz";
export * from "./bop";
src/core/foo/baz.ts 和 src/core/bar/baz.ts
export class Baz {
}
src/core/foo/bop.ts 和 src/core/core/bar/bop.ts
export class Bop {
}
另请参阅:https://www.typescriptlang.org/docs/handbook/modules.html
因为 typescript 3.8 已发布您可以添加出口的别名。
示例:
export * as utilities from "./utilities.js";
参考:https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html