我有一个基于React的组件库,我正在为其定义类型以帮助进行IntelliSense和类型检查(对于TS使用者)。从“ @ rebass / grid”重新导出的两个组件只是“ Box”和“ Flex”:
//src/components/Box.js
import { Box } from '@rebass/grid';
export default Box;
//src/components/Flex.js
import { Flex } from '@rebass/grid';
export default Flex;
如何为这些组件定义类型?由于这些实质上是样式化的组件,因此我实现了以下内容:
//index.d.ts
.
.
.
declare var Box: StyledComponent < "div",{},import("@rebass/grid").BoxProps > ;
declare var Flex: StyledComponent < "div",import("@rebass/grid").FlexProps > ;
.
.
.
这似乎可行-我使用TSC获得了IntelliSense和类型检查,但这是为只是重新导出第三方依赖项的自定义组件定义类型的最佳方法吗?