hibiken / react-places-autocomplete

React component for Google Maps Places Autocomplete
https://hibiken.github.io/react-places-autocomplete/
MIT License
1.38k stars 388 forks source link

Type error for KeyboardEventHandler #377

Open igoratf opened 3 years ago

igoratf commented 3 years ago

Do you want to request a feature or report a bug? Bug

What is the current behavior? I am trying to use the lib with TypeScript and getting an error related to KeyboardEventHandler:

Types of property 'onKeyDown' are incompatible.
      Type 'KeyboardEventHandler<Element>' is not assignable to type 'KeyboardEventHandler<HTMLInputElement>'.
        Types of parameters 'event' and 'event' are incompatible.
          Property 'code' is missing in type 'KeyboardEvent<HTMLInputElement>' but required in type 'KeyboardEvent<Element>'

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Just following the docs is throwing this compilation error for the input element.

What is the expected behavior? Changing onKeyDown: React.KeyboardEventHandler to onKeyDown: React.KeyboardEventHandler<HTMLInputElement> seems to work properly and compile.

Which versions of ReactPlacesAutocomplete, and which browser / OS are affected by this issue? "react-places-autocomplete": "^7.3.0", "@types/react-places-autocomplete": "^7.2.8",

mikestecker commented 3 years ago

Having the same issue. The bug seems to happen with @types/react and @types/react-dom present in the package.json. Removing these dependencies solves the problem. Another way of solving is to upgrade React and these @types packages to React 17

SalahAdDin commented 4 months ago

Having the same issue. The bug seems to happen with @types/react and @types/react-dom present in the package.json. Removing these dependencies solves the problem. Another way of solving is to upgrade React and these @types packages to React 17

I am having this issue even with React 18.