I have no errors in syntax (event.target as HTMLInputElement)
, and Typescript checks file as A-OK, but it fails to compile, and ends with an error. I am using React 18 alpha with Typescript support (app created with create-react-app).
This is the function:
const handleOnKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
if (event.code === "Enter") {
navigate(api.searchEndpoint + (event.target as HTMLInputElement).value);
}
};
Everything is OK and green in VS Code, and the syntax is ok, but when I try to compile it, i got this error:
src/components/elements/Search.tsx
Line 16:51: Parsing error: Unexpected token, expected ","
14 | const handleOnKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
15 | if (event.code === "Enter") {
> 16 | navigate(api.searchEndpoint + (event.target as HTMLInputElement).value);
Does somebody know what is the problem??