Vue:在 TypeScript 中使用“export * as”时模块解析失败

我有一个index.ts文件可以导出我所有的助手函数。为了以更方便的方式导入它们,我想使用export asTypeScript 3.8 的功能。


所以这是我的代码:


// index.ts

export * from './logging';

export * as TypeHelper from './types';

export * as ValidationHelper from './validation';

这是我在运行时遇到的错误npm run serve:


ERROR  Failed to compile with 1 errors                                                                                                                                               13:44:55


error  in ./src/services/helpers/index.ts


Module parse failed: Unexpected token (2:9)

File was processed with these loaders:

 * ./node_modules/cache-loader/dist/cjs.js

 * ./node_modules/@vue/cli-plugin-typescript/node_modules/ts-loader/index.js

 * ./node_modules/eslint-loader/index.js

You may need an additional loader to handle the result of these loaders.

| export * from './logging';

> export * as TypeHelper from './types';

| export * as ValidationHelper from './validation';


 @ ./src/plugins/router/index.ts 3:0-41 92:8-11 98:8-11

 @ ./src/main.ts

 @ multi (webpack)-dev-server/client?http://192.168.179.4:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.ts


Type checking in progress...

No type errors found

Version: typescript 3.9.7

我怎样才能解决这个问题?


阿晨1998
浏览 457回答 1
1回答

牧羊人nacy

根据 Mozilla 的说法,该语法不在当前规范中。那可能是 ES12export * from …; // does not set the default exportexport * as name1 from …; // Draft ECMAScript® 2O21现在,您可以导入它们,然后再导出它们。import * as TypeHelper from './types';export TypeHelper;
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript