- Notifications
You must be signed in to change notification settings - Fork4.3k
Contribute an alternative typing example for forms sample#24
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
ghost commentedJun 8, 2018 • edited by ghost
Loading Uh oh!
There was an error while loading.Please reload this page.
edited by ghost
Uh oh!
There was an error while loading.Please reload this page.
Hi, onMaskClick=(e:React.MouseEvent<HTMLDivElement>) Also, some events may don't have params so developer should not be injecting the types, but in your case you add unnecessary typings that may affect readability. What you think@sw-yx ? |
TomasHubelbauer commentedJun 8, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Like I said, this is an alternative, either you describe the type in the method signature, or you use the provided handler type in React TypeScript types and then you don't have to specify the argument types yourself as you are enforcing a type of the whole delegate. Essentially these is a shortcut to not having to specify the delegate type yourself, you already have it in React, but it's not really a shortcut, because you have to type about the same amount anyway. But for me I look to use the out of the box stuff wherever possible as a matter of principle, even if in this case it's same different in effort to type. |
swyxio commentedJun 8, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
interesting. I would say this is similar enough that we should just make it a one-liner to let people know it exists. doesn't really need more than that. I would also put in your explanation in the details/summary tag so that people can learn about delegate types (I don't really know about them). out of curiosity@TomasHubelbauer - how did you learn about React.ChangeEventHandler? I have never even seen it before. Is there some other resources you recommend? thank you for contributing btw. |
TomasHubelbauer commentedJun 8, 2018
I found it on my own reading the TypeScript types for React. I agree with making it a one-liner for comparison. My preference for this comes from the fact that this is an out of the box type which covers not only the argument types, but the type of the entire handler method, so while it's the same amount of work to type this, you are using a "blessed" type instead of making up an ad-hoc inferred type ( |
swyxio commentedJun 8, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
cool, I'll make minor edits and merge. I would argue the opposite, the less |
shorten React.ChangeEventHandler example and move to discussion
swyxio commentedJun 8, 2018
thanks for the contribution!! |
I like to use this, I think it boils down to a preference, but maybe it's worthwhile to showcase both?