【问题标题】:Create container module - export * as x from 'y'创建容器模块 - 从 'y' 导出 * 作为 x
【发布时间】:2018-03-14 18:15:40
【问题描述】:

我在一个模块中有这个:

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.

【问题讨论】:

    标签: typescript typescript2.0 tsc


    【解决方案1】:

    您可以从以下模块中导出所有元素(不允许重命名):

    export * from '../file.ts';
    

    或者您可以导出特定元素并根据需要重命名它们:

    export {Class1, Class2 as Class3} from '../file.ts';
    

    再出口文件:https://www.typescriptlang.org/docs/handbook/modules.html

    【讨论】:

    • 是的,你好像不能在一行中做到这一点
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-12
    • 1970-01-01
    • 1970-01-01
    • 2019-09-24
    • 2021-04-01
    相关资源
    最近更新 更多