patw0929 / react-intl-tel-input

Rewrite International Telephone Input in React.js. (Looking for maintainers, and PRs & contributors are also welcomed!)
https://patw0929.github.io/react-intl-tel-input/
MIT License
283 stars 222 forks source link

Incorrect type for geoIpLookup prop #408

Open usajjad123 opened 1 year ago

usajjad123 commented 1 year ago

The type of the geoIpLookup is incorrectly defined in IntTelInput.d.ts

Expected Behavior

It should be defined as a function taking callback as an argument: geoIpLookup?: (callback: (countryCode: string) => void) => void

This can be seen in the documentation and code too:

Screenshot 2022-11-14 at 8 15 27 PM Screenshot 2022-11-14 at 8 15 39 PM

Current Behavior

It is incorrectly defined as: geoIpLookup?: (countryCode: string) => void

Screenshot 2022-11-14 at 8 09 35 PM

This causes typescript error when providing geoIpLookup:

Screenshot 2022-11-14 at 8 11 22 PM Screenshot 2022-11-14 at 8 11 30 PM

Possible Solution

Only needed slight change in the type as suggested above

Steps to Reproduce

  1. Installed react-intl-tel-input lastest version (8.2.0)
  2. Provide the geoIpLookup prop

Code:

<IntlTelInput
        preferredCountries={['ae', 'pk']}
        geoIpLookup={async function (cb) {
          const info = await getIpInfo() // calling the ipinfo.io api
          const countryCode = info && info.country ? info.country : 'pk'
          cb(countryCode)
        }}
        formatOnInit={false}
        format={false}
      />

Environment