Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add typescript support for onChange method #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Basanta-Kc
Copy link

The onChange method is providing us mobile number and country info on the first and second param but the type definition includes only one event param due to which the users are unable to access the second param and are getting this error
image
So in order to overcome this error, I have added the type definition for the onChange method as

  onChange: ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement> & ((mobileNumber: string, country: Country) => void);

and the type definition for the country (second param) as

type Country = {
  name: string;
  dialCode: string;
  countryCode: string;
}

After this, the user can access both params successfully without any ts errors
image

@ghost
Copy link

ghost commented Jun 6, 2022

Why was this PR was not merged?

@ghost
Copy link

ghost commented Jun 6, 2022

@alexplumb looks like a great fix

@viclafouch
Copy link

This package (https://github.com/viclafouch/mui-tel-input) handles this problem, supports both React 17 / 18

@peteranderss0n
Copy link

peteranderss0n commented Aug 4, 2022

Until this is merged you can bypass the typescript error by setting the parameter as nullable:
onChange={(value, country?) => {}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants