Expanding on @ShriHari's response, consider implementing a click handler function.
Here is an example:
interface MyMouseEvent {
x: number
y: number
}
interface Element {
onClick: (event: MyMouseEvent) => void
}
In some cases, your handler may not necessarily need the event object passed to it.
At times, all that matters is whether the function was called or not.
element.onClick = () => console.log('clicked')
Other times, you may require access to the event object.
element.onClick = (e) => console.log('clicked position', e.x, e.y)
Both of these options are completely type safe. There are no variables with incorrect types.
When invoking a function type, all parameters must be provided. However, when implementing a function type, you are not obligated to use all parameters. If they are unnecessary in your function, there is no need to include them. Thus, it is not essential to enforce the presence of all parameters.
The crucial aspect is ensuring that the existing parameters have the correct type.