是否存在通配符导出的语法? [英] Is there a syntax for wildcard export as?

查看:157
本文介绍了是否存在通配符导出的语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有导入语法:

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';

有没有办法为 * 而不是默认

(仅供参考我是试图从语句中删除 require

(FYI I'm trying to remove require from the statement):

export const foo = require('bar');

ng服务时,会抛出以下错误运行包括上面的 .ts

the error below is thrown when ng serve is run including the .ts above:


ERROR in src/app/@theme/components/aComp/aComp.loader.ts(6,20): error TS2304: Cannot find name 'require'.



推荐答案

不,那里不是,但有将此语法添加到语言的提案。

No, there is not, but there is 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 也在本地模块范围内。

which is actually even closer to export const foo = require('bar'); than export * as foo from 'bar';, as it does provide foo in the local module scope as well.

这篇关于是否存在通配符导出的语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆