如何在 Babel 中将 * 导出为命名空间?

How can I export * as namespace in Babel?

我正在使用 TypeScript 3.8 编写混合了 JS 和 TS 的代码。我写了以下行:

export * as Easing from './easing';

在 TypeScript 3.8 中应该是 fair game。但是,我正在使用 Webpack 进行编译,我没有使用 ts-loader,仅使用带有 TypeScript 预设的 babel-loader,而且 Babel 似乎不支持这种语法。我收到此错误:

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'

我该如何解决这个问题?

我之前在这里问过这个问题:

import * as Easing from './easing';
export { Easing }

试试这个

// ./some/someFile.ts

export function util1 () {
...
}

export function util2 () {
...
}

export function util3 () {
...
}

在您的索引或您导入的任何文件上的 yow 函数

// ./some/index.ts

export * as utils from "./someFile";

如果您遇到任何问题。

将您的 index.ts 更改为:

import * as utils from "./someFile";

export { utils };

或者我们可以使用旧的但始终受信任的默认形式:

// ./some/someFile.ts

function util1 () {
...
}

function util2 () {
...
}

function util3 () {
...
}

export default {
   util1,
   util2,
   util3
}

在指数

import utils from "./someFile";
export { utils };

// or
export { default as utils } from "./someFile";