【问题标题】:Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.ts在提供 \'--isolatedModules\' 标志时重新导出类型需要使用 \'export type\'.ts
【发布时间】:2023-01-14 06:05:57
【问题描述】:

我已经创建了多个接口,并希望从一个公共的 index.ts 文件中发送它们,如下所示:

--pages
------index.interface.ts
--index.ts

现在在我的index.ts 中,我正在导出如下内容:

export { timeSlots } from './pages/index.interface';

而我的index.interface.ts 看起来像这样:

export interface timeSlots {
  shivam: string;
  daniel: string;
  jonathan: string;
}

现在,当我尝试这样做时,它告诉我:

Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.ts(1205)

不确定为什么会出现此错误,有人可以帮忙吗?

【问题讨论】:

    标签: typescript


    【解决方案1】:

    您只需要在重新导出类型时使用此语法:

    export type { timeSlots } from './pages/index.interface';
    //     ^^^^
    // Use the "type" keyword
    

    或者,如果使用 >= 4.5 的 TypeScript 版本,您可以在之前使用 type modifier每个改为导出类型标识符:

    export { type timeSlots } from './pages/index.interface';
    //       ^^^^
    // Use the "type" keyword
    

    第二种方法允许您混合类型价值单个export 语句中的标识符:

    export { greet, type GreetOptions } from './greeting-module';
    

    greeting-module.ts 可能看起来像这样:

    export type GreetOptions = {
      name: string;
    };
    
    export function greet(options: GreetOptions): void {
      console.log(`Hello ${options.name}!`);
    }
    

    【讨论】:

    • 我将如何在 AWS Code 构建环境中执行此操作?例如,我从一个库中得到这个错误,并且在安装时,它提供了这个打字稿错误。
    猜你喜欢
    • 2020-08-27
    • 2019-05-12
    • 2016-03-02
    • 2019-06-10
    • 2019-01-10
    • 2019-05-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多