React: Constrain typed changed events to inputs, selects and textareas

This commit is contained in:
Patricio Zavolinsky
2017-01-31 09:36:05 +00:00
parent 08c30a2c3d
commit ec9bf7f229
2 changed files with 39 additions and 16 deletions
+15
View File
@@ -674,3 +674,18 @@ class SyntheticEventTargetValue extends React.Component<{}, { value: string }> {
});
}
}
React.DOM.input({
onChange: event => {
// `event.target` is guaranteed to be HTMLInputElement
event.target.value;
}
});
// A ChangeEvent is a valid FormEvent (maintain compatibility with existing
// event handlers)
type InputChangeEvent = React.ChangeEvent<HTMLInputElement>;
type InputFormEvent = React.FormEvent<HTMLInputElement>;
const changeEvent:InputChangeEvent = undefined as any;
const formEvent:InputFormEvent = changeEvent;