-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[Select] onChange
parameter has unknown
type in Select
component
#16065
Comments
As far as I can tell, you need to specify the type of the value, it's defaulted to unknown. onChange={(event: React.ChangeEvent<{ value: string }>) => onChange(event.target.value)} or onChange={(event) => seValue(event.target.value as string)} @oliviertassinari Can't find this in the migration guide |
In my opinion,
Which means that in this component,
I think the type |
If you want opt-out of strict types you can do so by using |
I tried this solution but it doesn't solve the issue. The error I got is:
|
Yes you need to either |
what is the best option for me to do at the moment? I know I can fix it by set it to |
Me neither which is why I changed it to
if (typeof value === 'string') {
// handle string
} else {
// something unexpected! throw? warn? ignore?
} This is what |
@zhaoyi0113 The snippet i provided works perfectly fine for me. @eps1lon I could make the select generic, so you can provide the type, with it defaulting to unknown |
Generics in props are very tricky. There was a lot of back and forth with it concerning the You can try it but please include some tests with automatic inference and explicit generic argument and interactions between the ´value´ prop type and the the Even if this all works it's still a hidden |
Correct, it can't, however, when the user specifically sets the type, should it not be up to them to make sure it matches? |
Then we don't need a type checker or am I misunderstanding something? If they have to make sure that it matches manually why can't they cast to |
I'm not arguing against this, I'm just saying it would be nice to be able to set the type. Or one of the examples from the docs: <Select<string | number>
value={state.age}
onChange={handleChange('age')}
>
<option value="" />
<option value={10}>Ten</option>
<option value={20}>Twenty</option>
<option value={30}>Thirty</option>
</Select> |
and getting 1 error as below: Error 1: |
|
This comment has been minimized.
This comment has been minimized.
onChange
parameter has unknown
type in Select
componentonChange
parameter has unknown
type in Select
component
I have the below code to use
Select
component but I get a type error when upgrading to 4.0.2.This is the error about
event.target.value
parameter. It says the value isunknown
.The text was updated successfully, but these errors were encountered: