Typescript 2.3.4, react 15.5.4 and react-bootstrap 0.31.0.
I have a FormControl and I want to do something when the user presses enter.
The cont
The type of onKeyPress should be KeyboardEventHandler, which can be written in either of the following ways:
handleKeywordKeypress: KeyboardEventHandler = e => {
// use e.keyCode in here
}
or
import { KeyboardEvent } from "react";
handleKeywordKeypress = (e: KeyboardEvent) => {
// use e.keyCode in here
};
As you identified in your answer, if you go with the second option, you need to specifically use KeyboardEvent from React.
Note that the keyCode is directly available as a property on e; you don't need to access it via the nativeEvent.
Also, the generic type parameter T should be the FormControl component, rather than its props, so you should change your other handler too.