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

标签 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。被迫将 isolatedModules=true。 我正在 CRA2.1 上制作组件库

最佳答案

加拿大税务局 v3.4.1促进类型再导出 --isolatedModules .包含@babel/preset-typescript在版本 v7.9.0+(参见相应的 Babel 版本和 announcement )和 TypeScript 支持 TS 3.8 type-only imports and exports .你现在可以写:

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

// or
import type { MyListType } from "./list/BoundList"
export type { MyListType }
// note additional "type" keyword

看看this answer有关 import/export 语法的更多信息。

关于reactjs - 如何创建启用了 isolatedModules=true 选项的包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53444390/

相关文章:

reactjs - React useState 与对象的最佳实践?

javascript - 对于使用的变量编译警告 no-unused-vars

reactjs - Next.js 域路由与子域

angular - 如何在 Angular Material 嵌套树中获取节点兄弟?

javascript - 如何找到 rollup 3.1.0 更新错误?

babeljs - babel 需要 es6-shim 吗?

reactjs - React 中只允许输入中的数字(antd 样式)

javascript - B 扩展 A : set in B will overwrite get

reactjs - 带有 Redux 的 Typescript,如何在不重新声明 Action 定义的情况下使用连接?

webpack - 模块构建失败(来自 ./node_modules/babel-loader/lib/index.js): TypeError: Cannot read property 'bindings' of null