Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 使用StateHandler和TypeScript重新组合,实现类型泄漏到组件?_Reactjs_Typescript_Definitelytyped_Recompose - Fatal编程技术网

Reactjs 使用StateHandler和TypeScript重新组合,实现类型泄漏到组件?

Reactjs 使用StateHandler和TypeScript重新组合,实现类型泄漏到组件?,reactjs,typescript,definitelytyped,recompose,Reactjs,Typescript,Definitelytyped,Recompose,我正在尝试使用来自recompose的和stateHandlers包装一个无状态函数组件。我发现我能做到这一点的唯一方法是,如果我调整我的证监会的道具,使其与“泄露”的状态处理程序的某些方面相匹配。我是做错了什么,还是这是recompose类型的一个缺陷 我的证监会: interface IProps { className?: string; isEditing: boolean; toggleEditing: () => void; } const MyCom

我正在尝试使用来自recompose的
和stateHandlers
包装一个无状态函数组件。我发现我能做到这一点的唯一方法是,如果我调整我的证监会的道具,使其与“泄露”的状态处理程序的某些方面相匹配。我是做错了什么,还是这是recompose类型的一个缺陷

我的证监会:

interface IProps {
    className?: string;
    isEditing: boolean;
    toggleEditing: () => void;
}

const MyComponent: React.SFC<IProps> = ({ className, isEditing, toggleEditing }) => (
    <button className={className} onClick={toggleEditing}>{isEditing ? 'stop editing' : 'start editing'}</button>
);

export default MyComponent;
但这不起作用,我在编译时遇到以下错误:

(32,43): Argument of type 'StatelessComponent<IProps>' is not assignable to parameter of type 'ComponentType<IProps & IToggleEditingState & IToggleEditingStateUpdaters>'.
  Type 'StatelessComponent<IProps>' is not assignable to type 'StatelessComponent<IProps & IToggleEditingState & IToggleEditingStateUpdaters>'.
    Type 'IProps' is not assignable to type 'IProps & IToggleEditingState & IToggleEditingStateUpdaters'.
      Type 'IProps' is not assignable to type 'IToggleEditingStateUpdaters'.
        Types of property 'toggleEditing' are incompatible.
          Type '() => void' is not assignable to type 'StateHandler<IToggleEditingState>'.
            Type 'void' is not assignable to type 'Partial<IToggleEditingState> | undefined'.
我必须更改
toggleEditing
,以匹配@types/recompose中定义的
StateHandler
的类型。我还需要添加索引器。这似乎是因为在@types/recompose中,
with stateholders
返回一个
可推断的ComponentEnhancerWithProps
,最终在遍历所有类型之后,仍然希望组件上有一个索引器


我在报告中注意到,他们正在定义证监会,然后将其全部打包在一个地方。因此,事实上,证监会实际上有奇怪的道具要求并不明显。我想自己定义我的SFC,这样我可以在其他情况下重用它。我是否正在超越预期的用例?我做错了什么吗?

一个谜团被解开了,我相信
(…有效载荷:any[])=>对象是
切换编辑的正确类型,正如主重组坞所说:“将状态对象属性和不可变更新程序函数以(…有效载荷:any[])=>对象的形式传递给基本组件。”这样就只剩下索引器了。
(32,43): Argument of type 'StatelessComponent<IProps>' is not assignable to parameter of type 'ComponentType<IProps & IToggleEditingState & IToggleEditingStateUpdaters>'.
  Type 'StatelessComponent<IProps>' is not assignable to type 'StatelessComponent<IProps & IToggleEditingState & IToggleEditingStateUpdaters>'.
    Type 'IProps' is not assignable to type 'IProps & IToggleEditingState & IToggleEditingStateUpdaters'.
      Type 'IProps' is not assignable to type 'IToggleEditingStateUpdaters'.
        Types of property 'toggleEditing' are incompatible.
          Type '() => void' is not assignable to type 'StateHandler<IToggleEditingState>'.
            Type 'void' is not assignable to type 'Partial<IToggleEditingState> | undefined'.
interface IProps {
    className?: string;
    isEditing: boolean;
    toggleEditing: (...payload: any[]) => any;
    [key: string]: any;
}