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

Revert "Make SyntheticEvent.target generic, not SyntheticEvent.currentTarget." #12239

Merged
1 commit merged into from Oct 31, 2016

Conversation

bbenezech
Copy link
Contributor

Reverts #11531

@bbenezech
Copy link
Contributor Author

#11508 (comment) for context.

Do not revert back without notifying me before.

@vvakame
Copy link
Member

vvakame commented Oct 25, 2016

sorry, @andy-ms could you check this PR?

@ghost
Copy link

ghost commented Oct 25, 2016

@huan086
Copy link
Contributor

huan086 commented Oct 25, 2016

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

@bbenezech
Copy link
Contributor Author

@huan086 😍

@bbenezech
Copy link
Contributor Author

bbenezech commented Oct 26, 2016

@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.

@tkrotoff
Copy link
Contributor

tkrotoff commented Oct 26, 2016

@huan086 @bbenezech
All React documentation and ecosystem uses e.target.value, filling an issue there would be a great idea. I suggest an online React demo (Plunker, jsfiddle...) to show that it is dangerous.

There is a high probability that somebody else will change back to target in the future.
I would suggest a note in the d.ts file above target: EventTarget about this.

@huan086
Copy link
Contributor

huan086 commented Oct 26, 2016

@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

joshaber added a commit to desktop/desktop that referenced this pull request Oct 26, 2016
Until they finally figure out what they’re doing. see
DefinitelyTyped/DefinitelyTyped#12239
@dsifford
Copy link
Contributor

Thank you so much for this @bbenezech 👍

@ghost ghost merged commit 2231526 into DefinitelyTyped:types-2.0 Oct 31, 2016
@kengorab
Copy link
Contributor

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.

@ghost
Copy link

ghost commented Oct 31, 2016

@bbenezech Could you make a PR adding a comment telling people not to change it back?

@Strato
Copy link
Contributor

Strato commented Nov 2, 2016

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.

@bbenezech
Copy link
Contributor Author

@Strato @kengorab How do you define Semver in the context of a typescript definition file? Specifically, what is its public API?
Or with a reduction proof attempt: what change can be made without potentially breaking a build?

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.
If that is the issue, do not do that. Instead use yarn lock, shrinkwrap or lock the last digit in package.json. Even semver libs should be expected to have regressions, and this ought not break your testing or production build.

@kengorab
Copy link
Contributor

kengorab commented Nov 2, 2016

each commit bumps the patch bit

I wasn't aware of that, sorry.

what change can be made without potentially breaking a build?

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 any to something more useful). Either of those could potentially break someone's build, I suppose, if they were incorrectly using a function or a type. But I think the onus would be on the user in that case, since they were implicitly relying on the incompleteness of the previous definition file.

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 foo(bar: number | string): number and its signature was changed to foo(bar: number): number, that would definitely be considered a breaking change, as far as an API would be concerned. I don't expect the versioning scheme to change for this repo though; keeping the major and minor in sync with the main lib is good practice.

non-deterministic npm builds

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.

@skeate
Copy link
Contributor

skeate commented Mar 1, 2018

Not to beat this dead horse any more, but with conditional types coming out in 2.8, could we add the & T back iff T is an empty element (e.g. HTMLInputElement)?

@karol-majewski
Copy link
Contributor

@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 EventTarget & T with just T, since every T extends the EventTarget interface anyway.

This would make React typings (and their dependants) work only with TypeScript ^2.8, though.

@skeate
Copy link
Contributor

skeate commented Jul 29, 2018

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).

This pull request was closed.
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.

None yet

10 participants