Reactjs 如何创建启用了isolatedModules=true选项的包?

Reactjs 如何创建启用了isolatedModules=true选项的包?,reactjs,typescript,babeljs,create-react-app,Reactjs,Typescript,Babeljs,Create React App,在一个文件中,我导出包中所有类的行,如下所示: export {default as BoundList, IBoundListOption, TBoundListFilterFn} from './list/BoundList'; 生成表单的错误: TS1205: Cannot re-export a type when the '--isolatedModules' flag is provided. 现在如何导出类 此问题发生在CRA2.1中。必须隔离模块=真。 我正在CRA2.1上制

在一个文件中,我导出包中所有类的行,如下所示:

export {default as BoundList, IBoundListOption, TBoundListFilterFn} from './list/BoundList';
生成表单的错误:

TS1205: Cannot re-export a type when the '--isolatedModules' flag is provided.
现在如何导出类

此问题发生在CRA2.1中。必须隔离模块=真。
我正在CRA2.1上制作一个组件库

Yes-
node\u模块/fork ts checker网页包plugin/package.json
是“版本”:“0.2.2”

这项更改似乎是在Microsoft/TypeScript#15538中进行的,因此如果使用2.3进行测试,则不会看到错误。但它将在2.4发布后开始崩溃

尽管如此,如果isolatedModules被重写为true,这一切都不应该成为问题。

(感谢您的链接)包含了一个解决方法,用于重新导出导入的类型。在这个问题上,有一个最佳的解决办法:

如果很清楚您正在导出类型,您仍然可以执行以下操作:

import { T as a_T } from "./a";
export type T = a_T;
您还可以从“/a”执行导出操作

如果我正确理解了GitHub的问题,那么只有TS类型可以重新导出,但是值(例如类)不能重新导出。因此,如果TS知道您正在导入类型(而不是类),那么您可以重新导出它

下面是另一个更简单的示例:

import { T } from "./a";
export type T = T;
CRA促进了该协议项下的转口贸易。版本
v7.9.0
+(请参阅相应的发行版和)和类型脚本支持TS 3.8。你现在可以写:

export type { MyListType } from "./list/BoundList"

// or
import type { MyListType } from "./list/BoundList"
export type { MyListType }
// note additional "type" keyword
查看
导入
/
导出
语法的更多信息。

tsconfig.json

"compilerOptions": {
    ...
    "isolatedModules": false,
    ...
}

这里似乎有一些讨论,包括解决方法。请在您的答案中添加一些描述/解释,并解释其工作原理和解决问题的方法。