有导入语法:
import * as foo from 'bar';
我也尝试过:
export * as foo from 'bar';
但这引发了错误:
ERROR in src/app/@theme/components/aComp/aComp.loader.ts(1,10): error TS1005: 'from' expected. src/app/@theme/components/aComp/aComp.loader.ts(1,13): error TS1005: ';' expected. src/app/@theme/components/aComp/aComp.loader.ts(1,17): error TS1005: ';' expected. src/app/@theme/components/aComp/aComp.loader.ts(1,22): error TS1005: ';' expected.
还有导出语法:
export { default as foo } from 'bar';
相对于*
,default
可以做到这一点吗?
(仅供参考,我正在尝试从语句中删除require
)
export const foo = require('bar');
运行ng serve
包括上面的.ts
时会引发以下错误:
ERROR in src/app/@theme/components/aComp/aComp.loader.ts(6,20): error TS2304: Cannot find name 'require'.
答案 0 :(得分:3)
不,没有,但是有a proposal to add this syntax to the language。
当前,您将需要使用
import * as foo from 'bar';
export { foo }; // verbose: { foo as foo }
实际上比export const foo = require('bar');
更接近export * as foo from 'bar';
,因为它确实在本地模块范围内提供了foo
。