Type of EventHandler's this #3237
thatoddmailbox
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
(Sorry if this is in the wrong category or should be an issue instead, this is my first time using GitHub Discussions!)
I'm trying to upgrade an application of mine from Preact 10.5.13 to 10.5.14, and seems like in this pull request, the type of
EventHandler
'sthis
was changed to benever
. This broke a component that was taking aJSX.MouseEventHandler<HTMLAnchorElement>
in its props and then trying to.call
that function with anHTMLAnchorElement
.Here's a simplified version of the component:
This works in 10.5.13, but in 10.5.14 gives a
TS2345: Argument of type 'HTMLAnchorElement' is not assignable to parameter of type 'never'.
on the line containingthis.props.onClick.call(this._ref, e);
.I'm not sure I get why the type was changed to
never
? My understanding is that, forEventHandler
,this
should be the DOM element that had the event, so the original type definition would be correct?I realize that this is also probably a bit of a weird use case (in my scenario, I could just make
onClick
a() => void
), so should components just avoid trying to do anything unusual withEventHandler
?Beta Was this translation helpful? Give feedback.
All reactions