我在一个模块中有这个:
export const Category = require('./category');
export const Roles = require('./roles');
export const FunctionalTeams = require('./functional-team');
export const WorkSteams = require('./workstream');
我尝试将其更改为TS导入:
export * as Category from './category';
export * as Roles from './roles';
export * as FunctionalTeams from './functional-team';
export * as WorkSteams from'./workstream';
但这不起作用,tsc甚至不识别该语法,我看到这些错误:
models/enums/index.ts(17,22): error TS1005: ';' expected.
models/enums/index.ts(17,27): error TS1005: ';' expected.
models/enums/index.ts(18,10): error TS1005: 'from' expected.
models/enums/index.ts(18,13): error TS1005: ';' expected.
models/enums/index.ts(18,19): error TS1005: ';' expected.
答案 0 :(得分:2)
您可以从以下模块中导出所有元素(不允许重命名):
export * from '../file.ts';
或者您可以导出特定元素并根据需要重命名:
export {Class1, Class2 as Class3} from '../file.ts';
转口文件:https://www.typescriptlang.org/docs/handbook/modules.html