-
-
Notifications
You must be signed in to change notification settings - Fork 433
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
Types for values on events #2491
Labels
enhancement
New feature or request.
Comments
Hi @ersinakinci I recommend using a type guard to add a type to the target. <div>
<input
onChange={(e) => {
if (e.currentTarget instanceof HTMLInputElement) {
e.currentTarget.value // ...
}
}}
/>
</div> But, indeed, it will be inconvenient, and it has the proper type with React. @usualoma What do you think about it? Do you think we should implement it? |
In React we can do something like this @yusukebe : import { ChangeEvent } from "react";
const validateField = (event: ChangeEvent<HTMLInputElement>) {
console.log(event.target.value);
} I think it's something good to implement because it was close to Dom. |
As an alternative we can use type guard or type annotation: import { ChangeEvent } from "react";
const validateField = (event: Event) {
console.log((event.target as HTMLInputElement).value);
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is the feature you are proposing?
It would be nice to have
event.target.value
as a type that can be accessed.The text was updated successfully, but these errors were encountered: