Why is `BoundEventHandler` typed this way?
The type for
BoundEventHander
is,
In order to use it, I need to do something like const handler = BoundEventHandler<T,E>[0]
, note the [0]
at the end, which seems weird. Why is it typed this way? How is this type expected to be used?5 Replies
this is for the
onClick={[callback, data]}
syntaxSo it's normal to use
[0]
when typing a bound event handler function?
Since the interface has Handler
in the name, it would seem that it is the type for a function, not a tupleit is a tuple type, but it's declared this way since interfaces that are redeclared extend their own types
whether or not it needs to be typed this way can be up for discussion though
Thanks @lxsmnsyc 🤖 . I guess I asked about the type because I was a bit surprised by the type syntax needed to type the handler, although perhaps a better question is how are handlers typically typed?
it's either just the plain callback or that
it's a union, so to speak