【发布时间】:2019-02-21 16:26:01
【问题描述】:
提前为这个模糊的标题道歉,我的问题很难回答。
我正在尝试同时使用 React、Recompose 和 Typescript,但是在尝试将 props 传递到我的组件时出现以下错误:
[ts] Property 'bar' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<{}, any, any>> & Readonly<{ children?: ReactNode; }> & Readonly<{}>'.
组件是这样导入的:
import TestComponent from './TestComponent'
并像这样调用:
<TestComponent bar="hello"/>
这是我的组件文件夹的结构:
├── TestComponent.tsx
├── TestComponentContainer.ts
└── index.ts
index.ts如下:
import TestComponentContainer from './TestComponentContainer'
export default TestComponentContainer
TestComponent.jsx如下:
import * as React from 'react'
interface IProps {
foo: string
bar: string
}
const TestComponent: React.SFC<IProps> = ({ foo, bar }) => (
<div>
<p>{foo}</p>
<p>{bar}</p>
</div>
)
export default TestComponent
TestComponentContainer.ts如下:
import { compose, withProps } from 'recompose'
import TestComponent from './TestComponent'
export default compose(
withProps({
foo: 'stringy string string',
}),
)(TestComponent)
我知道我错过了某种类型声明,用于传递正在传递的道具,但我一生都无法弄清楚我应该做什么。
编辑:
此外,如何使用嵌套方法做到这一点:
export default compose(
setDisplayName('PlayerCardContainer'),
withMutation(mutation),
withHandlers(createHandlers),
)(PlayerCard)
【问题讨论】:
标签: javascript reactjs typescript recompose