在模块上找不到导出

Pla*_*256 4 rollup typescript babeljs

我有一个库,在导出接口的文件之一中:

export interface MyInterface {
...
}
Run Code Online (Sandbox Code Playgroud)

并且有一个默认导出,它是一个react组件。

index.ts文件上,我导入了一些东西,然后将它们重新导出:

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

export { Something, OtherStuff, ExportDefault, MyInterface };
Run Code Online (Sandbox Code Playgroud)

编译时出现错误:

MyInterface不是由QuestionFile导出的。

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

有更好的方法吗?

如果我做:

export * from "./QuestionFile"

它有效,否则会破坏我的构建。

可以在此存储库中找到有关发生情况的示例:https : //github.com/PlayMa256/typescript-babel-error

Mat*_*hen 6

重新导出类型是已知的TypeScript构造之一,在使用Babel编译TypeScript时不起作用,因为它们需要跨文件信息。您可以启用isolatedModulesTypeScript编译器选项,以在使用tsc(不是Babel)进行编译或在IDE中使用TypeScript语言服务时将这些构造报告为错误。 export *是一种解决方法;此问题中描述的另一个是使用类型别名而不是重新导出。另一个解决方法是将常量与接口合并。(这是一种技巧,但避免了其他方法的某些缺点。)

export interface testInterface {
    name?: string;
}
export const testInterface = undefined;
Run Code Online (Sandbox Code Playgroud)


Sév*_*ais 5

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

\n
\n

作为 TypeScript 3.8 中的解决方案,我们\xe2\x80\x99 添加了用于仅类型导入和导出的新语法。

\n
\n
import type { SomeThing } from "./some-module.js";\n\nexport type { SomeThing };\n
Run Code Online (Sandbox Code Playgroud)\n