Why does MouseEvent.toElement return Node?
I’d assume it should return Element, or the method should be renamed toNode.
As it stands, having the dart editor warn me about accessing the style property when I write the following is less than ideal:
event.toElement.style.textDecoration = "line-through";
I believe it’s called
toElement()to keep it aligned with what we have already in the DOM/JavaScript land. It was named by Microsoft long ago and has been adopted in several browsers today. So, I think in Dart we wanted to keep the same name.However, whether we should annotate it to return
NodeorElement, that’s a good question. I believe in almost every (if not all) cases the returned object is indeed anElementand it would be nicer if it was typed to return anElement. However, there may be corner cases where it actually returns aNode(remember, elements extend nodes). With quick testing, I couldn’t find any such case. Maybe with manual event firing.Maybe the Dart engineer behind this choice can shed us some light.