代码之家  ›  专栏  ›  技术社区  ›  PlayMa256

在模块上找不到导出

  •  2
  • PlayMa256  · 技术社区  · 6 年前

    export interface MyInterface {
    ...
    }
    

    还有一个默认的导出,它是一个react组件。

    index.ts

    import Something from "./Something";
    import OtherStuff from "./OtherStuff";
    import ExportDefault, { MyInterface } from "./QuestionFile";
    
    export { Something, OtherStuff, ExportDefault, MyInterface };
    

    编译时,会出现一个错误:

    我的目标是,无论谁导入我的库,都能够导入该类型定义以供使用。

    如果我这样做了:

    export * from "./QuestionFile"

    在这个存储库中可以找到一个关于发生了什么的示例: https://github.com/PlayMa256/typescript-babel-error

    1 回复  |  直到 6 年前
        1
  •  12
  •   Matt McCutchen    6 年前

    重新导出类型是已知的TypeScript构造之一,在使用Babel编译TypeScript时不起作用,因为它们需要跨文件信息。您可以启用 isolatedModules TypeScript编译器选项,用于在使用编译时将这些构造报告为错误 tsc (不是Babel)或在IDE中使用TypeScript语言服务。 export * this issue

    export interface testInterface {
        name?: string;
    }
    export const testInterface = undefined;
    
        2
  •  0
  •   Séverin Beauvais    4 年前

    https://devblogs.microsoft.com/typescript/announcing-typescript-3-8-beta/ :

    作为TypeScript3.8中的一个解决方案,我们为纯类型导入和导出添加了一个新语法。

    import type { SomeThing } from "./some-module.js";
    
    export type { SomeThing };