react-redux connect()和错误TS2345

时间:2017-06-05 13:58:53

标签: reactjs typescript react-redux

我无法弄清楚为什么此代码无法构建并出现以下错误:

Input: Candidates - [A,B,C,D,E] and 3 questions.

Step1. Let's generate all the possible combinations of the candidates,
       ex:- A,B,C,D,E | A,C,B,D,E ..... D,E,B,C,A etc.

Step2. Take first string A,B,C,D,E and make use of two pointers, one
       starting at beginning and other starting at the end, like this

       A B C D E
       ^       ^
       |       |

Step3. So for first question our order will be like this - A,B,C,D,E
Step4. For the next question increment beginning pointer and decrement ending pointer.

Step5. So for the next question our pointers look like this

       A B C D E
         ^   ^
         |   |

Step6. So out of the calculated permutations select that permutation which
       has B in the starting and D in the ending.
       So for the second question, our configuration would look like this  
       B,A,C,E,D

Step7. Increment the same starting pointer and decrement the ending pointer
       in the same fashion for the next questions also.

Step8. Now when increment pointer reaches the end or decrement pointer
       reaches the start then reverse them and we took A,B,C,D,E as our
       string to move pointers.
       Now take another string to move pointers on.

我正在运行typescript 2.3.3并且@ types / react-redux的版本是4.4.41。

(43,3): error TS2345: Argument of type 'typeof Day' is not assignable to parameter of type 'Component<Props | (Props & ConnectProps & DispatchProps)>'.
  Type 'typeof Day' is not assignable to type 'StatelessComponent<Props | (Props & ConnectProps & DispatchProps)>'.
    Type 'typeof Day' provides no match for the signature '(props: (Props & { children?: ReactNode; }) | (Props & ConnectProps & DispatchProps & { children?: ReactNode; }), context?: any): ReactElement<any>'.

我想避免装饰者,只要他们是实验性的。

2 个答案:

答案 0 :(得分:1)

  

我想避免装饰者,只要他们是实验性的。

接近它的错误方法。他们像JSX一样工作 。当前的类型定义假设您将使用装饰器。

更多

如果您仍然不想使用装饰器,则必须编写自己的类型定义,然后覆盖redux中的类型定义,这两者都不是简单的挑战。欢迎您使用它们来获取乐趣,但需要的时间比有用的 SO答案中所需的时间长。

答案 1 :(得分:0)

我发现这是“ @ types / react”问题:“ ^ 16.9.2”。

我将其降级并修复为“ @ types / react”:“ 16.0.38”,并且可以正常工作。

使用示例作为指南https://redux.js.org/recipes/usage-with-typescript,但正是在此沙箱中,我发现他们在以下位置使用了固定版本:https://codesandbox.io/s/w02m7jm3q7

不确定为什么,也许不确定类型是否是TS的新内容,但是通过使用此方法 “ @ types / react”:“ 16.0.38”修复了TS2345错误。我可能会问海报。

希望有帮助。

欢呼

哈维尔