[英]flowtype error with react's synthetic event
我其实是在尝试学习flowtype。 在我的反应应用中,我有一个可重复使用的TextArea组件,这是道具声明:
type props = {
fill?: boolean,
large?: boolean,
blue?: boolean,
red?: boolean,
onChange: (
e: SyntheticEvent<HTMLInputElement> & { currentTarget: HTMLInputElement },
) => void,
value: string
};
当我在其他组件中重用它时:
<TextArea value={this.state.note} onChange={this.changeNote} />
changeNote方法:
changeNote = (
e: SyntheticEvent<HTMLInputElement> & { currentTarget: HTMLInputElement },
) => {
this.setState({ note: e.currentTarget.value });
};
运行流程时出现此错误:
app/components/pages/bills/BillAddPage.js:256
256: <TextArea value={this.state.note} onChange={this.changeNote} />
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ React element `TextArea`
21: e: SyntheticEvent<HTMLInputElement> & { currentTarget: HTMLInputElement },
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ intersection type. Expected polymorphic type instead of. See: app/components/atoms/TextArea.js:21
141: e: SyntheticEvent<HTMLInputElement> & { currentTarget: HTMLInputElement },
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ class type: SyntheticEvent
这有什么不对?
您应该使用特定的SyntheticEvent
,例如SyntheticInputEvent
。 🙂
SyntheticEvent<T>
for Event SyntheticAnimationEvent<T>
SyntheticCompositionEvent<T>
SyntheticInputEvent<T>
SyntheticUIEvent<T>
SyntheticFocusEvent<T>
SyntheticKeyboardEvent<T>
SyntheticMouseEvent<T>
SyntheticDragEvent<T>
SyntheticWheelEvent<T>
SyntheticTouchEvent<T>
SyntheticTransitionEvent<T>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.