[英]How can I export * as namespace in Babel?
I am working on code that is a mixture of JS and TS, using TypeScript 3.8.我正在使用 TypeScript 3.8 编写 JS 和 TS 的混合代码。 I wrote the following line:
我写了以下行:
export * as Easing from './easing';
Which should be fair game in TypeScript 3.8.在 TypeScript 3.8 中应该是公平的游戏。 However, I am compiling using Webpack, and I am not using
ts-loader
, only babel-loader
with the TypeScript preset, and it seems like Babel does not support this syntax.但是,我正在使用 Webpack 进行编译,并且我没有使用
ts-loader
,仅使用带有 TypeScript 预设的babel-loader
,并且似乎 Babel 不支持此语法。 I'm getting this error:我收到此错误:
ERROR in./src/index.ts Module build failed (from./node_modules/babel-loader/lib/index.js): SyntaxError: /home/laptou/projects/my-project/src/index.ts: Unexpected export specifier type 30 | default as Clock, addUpdateListener, after, chain, clock, infinite, tween 31 | } from './clock'; 32 | export * as Easing from './easing'; | ^^^^^^^^^^^ 33 | export type { Tween, TweenOptions, TweenStatus } from './tween'; 34 | export { default as InterpolateTween } from './tween/interpolate'
How can I fix this?我怎样才能解决这个问题?
I've asked this question before here: namespace export from index.js我之前在这里问过这个问题: namespace export from index.js
import * as Easing from './easing';
export { Easing }
try this尝试这个
// ./some/someFile.ts
export function util1 () {
...
}
export function util2 () {
...
}
export function util3 () {
...
}
An on your index or any file you import yow functions一个在你的索引或你导入你的函数的任何文件上
// ./some/index.ts
export * as utils from "./someFile";
If by any means you get some problems.如果无论如何你会遇到一些问题。
Change your index.ts to:将您的 index.ts 更改为:
import * as utils from "./someFile";
export { utils };
or we could used the old but always trusted default form:或者我们可以使用旧的但始终受信任的默认形式:
// ./some/someFile.ts
function util1 () {
...
}
function util2 () {
...
}
function util3 () {
...
}
export default {
util1,
util2,
util3
}
at the index在索引处
import utils from "./someFile";
export { utils };
// or
export { default as utils } from "./someFile";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.