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
Revert "Make SyntheticEvent.target generic, not SyntheticEvent.currentTarget." #12239
Conversation
#11508 (comment) for context. Do not revert back without notifying me before. |
sorry, @andy-ms could you check this PR? |
Pinging @Emm, @Rohitlodha, @s-panferov, @nantaphop, @huan086, @alitaheri |
I'll just reiterate my issue that started it all #10811 So merge this ASAP e.currentTarget should be generic. I've no idea why so many people use e.target (including me in the past), introducing stupid bugs where I try to get attributes from the wrong element |
@huan086 😍 |
@vvakame please merge ASAP, this is not a good idea to leave react.d.ts in this state. It has caused enough bugs and confusion as it is. |
@huan086 @bbenezech There is a high probability that somebody else will change back to |
@tkrotoff I glanced through both links and do see that e.currentTarget is used. e.target is only used in the special case of input onChange, which is guaranteed to come from the input. So no issue there. I like the idea of adding a note to remind people |
Until they finally figure out what they’re doing. see DefinitelyTyped/DefinitelyTyped#12239
Thank you so much for this @bbenezech 👍 |
Can this be the last time this changes, or at least not have them be patch-level changes? We've had our build broken twice now because of this. |
@bbenezech Could you make a PR adding a comment telling people not to change it back? |
We had our build broken twice as well. Make up your mind and please stop this mess. And when you do breaking changes, please bump version according to semver semantics. |
@Strato @kengorab How do you define Semver in the context of a typescript definition file? Specifically, what is its public API? AFAIK, versioning is automatic with changes on branch types-2.0: each commit bumps the patch bit. Major and minor bits are from the underlying lib. I may be wrong, but to me it looks like you have non-deterministic npm builds and whine on maintainers when it blows at your face. |
I wasn't aware of that, sorry.
Adding a function usually qualifies as a non-breaking change, so in the context of a type definition file, I'd equate that to either adding a definition for a function that was previously left out of the file, or refining a type to something more specific (say, changing an instance of I don't think adding completeness should count as a breaking change, but altering a type should, in my opinion. If I had a function
I do use yarn locally, but our build boxes still use npm. The change to yarn there is outside of my control. I'll definitely be more conscientious of locking down version numbers in the future for type definition files, though. |
Not to beat this dead horse any more, but with conditional types coming out in 2.8, could we add the |
@skeate Do you mean like this? /**
* @see https://developer.mozilla.org/en-US/docs/Glossary/Empty_element
*/
type EmptyHTMLElement =
| HTMLAreaElement
| HTMLBaseElement
| HTMLBRElement
| HTMLTableColElement
| HTMLEmbedElement
| HTMLHRElement
| HTMLImageElement
| HTMLInputElement
| HTMLLinkElement
| HTMLMetaElement
| HTMLParamElement
| HTMLSourceElement
| HTMLTrackElement; interface SyntheticEvent<T = Element> {
/* ... */
target: T extends EmptyHTMLElement
? EventTarget & T
: EventTarget;
} We could even go one step futher and replace This would make React typings (and their dependants) work only with TypeScript ^2.8, though. |
Yep, that's what I was thinking. I'm not sure if/how this system handles different typescript versions (I see this note but I'm not sure what the implications of that are). |
Reverts #11531