允许将对象(用于CSS模块)传递给ReactCSSTransitionGroup以进行Flow验证

时间:2017-04-16 14:51:39

标签: reactjs flowtype css-modules reactcsstransitiongroup

我正在使用ReactCSSTransitionGroup,CSS模块和流程。

<ReactCSSTransitionGroup
  transitionName={{
    enter: slideTransition.enter,
    enterActive: slideTransition.enterActive,
    leave: slideTransition.leave,
    leaveActive: slideTransition.leaveActive,
  }}
  transitionEnterTimeout={500}
  transitionLeaveTimeout={500}
>
  { /* ... */ }
</ReactCSSTransitionGroup>

因为我使用的是CSS模块,所以我必须将每个enterenterActiveleaveleaveActive传递给对象的一个​​键。

但是,此文件的flow检查告诉我以下内容:

src/components/Category.jsx:153
153:           transitionName={{
                               ^ object literal. This type is incompatible with
 14:     transitionName: string | ReactCSSTransitionGroupNames,
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ union: string | ReactCSSTransitionGroupNames. See lib: flow-typed/npm/react-addons-css-transition-group_v15.x.x.js:14
  Member 1:
   14:     transitionName: string | ReactCSSTransitionGroupNames,
                           ^^^^^^ string. See lib: flow-typed/npm/react-addons-css-transition-group_v15.x.x.js:14
  Error:
  153:           transitionName={{
                                 ^ object literal. This type is incompatible with
   14:     transitionName: string | ReactCSSTransitionGroupNames,
                           ^^^^^^ string. See lib: flow-typed/npm/react-addons-css-transition-group_v15.x.x.js:14
  Member 2:
   14:     transitionName: string | ReactCSSTransitionGroupNames,
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ReactCSSTransitionGroupNames. See lib: flow-typed/npm/react-addons-css-transition-group_v15.x.x.js:14
  Error:
   14:     transitionName: string | ReactCSSTransitionGroupNames,
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ property `appear`. Property not found in. See lib: flow-typed/npm/react-addons-css-transition-group_v15.x.x.js:14
  153:           transitionName={{
                                 ^ object literal

有没有办法可以解决这个错误,或者在能够使用CSS模块时传递正确的类型?

1 个答案:

答案 0 :(得分:0)

(this->*(_requests[0].parse_routine))(Record); 使用严格的类型列表:

transitionName

在您的情况下,您错过了所需的export const nameShape = React.PropTypes.oneOfType([ React.PropTypes.string, React.PropTypes.shape({ enter: React.PropTypes.string, leave: React.PropTypes.string, active: React.PropTypes.string, }), React.PropTypes.shape({ enter: React.PropTypes.string, enterActive: React.PropTypes.string, leave: React.PropTypes.string, leaveActive: React.PropTypes.string, appear: React.PropTypes.string, appearActive: React.PropTypes.string, }), ]); appear道具。

appearActive也会通过以下行通知您:

flow