S
SolidJS•3mo ago
aryzing

Why is `BoundEventHandler` typed this way?

The type for BoundEventHander is,
interface BoundEventHandler<T, E extends Event> {
0: (
data: any,
e: E & {
currentTarget: T;
target: DOMElement;
}
) => void;
1: any;
}
interface BoundEventHandler<T, E extends Event> {
0: (
data: any,
e: E & {
currentTarget: T;
target: DOMElement;
}
) => void;
1: any;
}
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
thetarnav
thetarnav•3mo ago
this is for the onClick={[callback, data]} syntax
aryzing
aryzing•3mo ago
So 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 tuple
lxsmnsyc
lxsmnsyc•3mo ago
it 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
aryzing
aryzing•3mo ago
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?
lxsmnsyc
lxsmnsyc•3mo ago
it's either just the plain callback or that it's a union, so to speak
Want results from more Discord servers?
Add your server
More Posts
How can you get the id of element body when its id is changed?How can you get the id of body element when changing its id, is there any hooks or something like thIs anyone detecting light vs dark mode on their site>For example, I frequently use ```jsx const isMobileSize = useMediaQuery("(max-width:600px)"); ```how to end response without using "nativeEvent"?what would be a better way of writing the following inside of `middleware`? ```javascript  event.nawhat's the difference between? createResource andcreateAsyncand who can write about createAsync in more detail essentially createAsync is a wrapper over createRHow to create a reactive localstorage?Hi, I need to create a reactive localstorage for localization on my site but I don't know how to do How do i make a list properly reactive to state changes?So I have this for loops that iterates in an array of data fetched on page load, i devided the sortiSolidStart - Create T3 EquivalentIs there any stack like create t3 app but for SolidStart? Also what component library y’all using?Can't use import `assert {"type":"json"}``whenever I try to import a .json document with the assert specified, i get errors about missing babeWas watching Theo's video and wondered if solid had a good way to do thishttps://youtu.be/jYV1VDhw7E8?t=447 It involves saving a state when a components moves position in tHow to use load property of <Route>I haven't been able to figure out how to use `<Route>`'s `load` function and haven't found a complet