Following up on this, casting the result of document.createElement, goog.dom.createElement, canvas.getContext, and similar examples is so common that it would be wonderful if the Closure Compiler could automatically type the return value of these commonly-used functions, where it can reasonably do so.
i.e., it would be wonderful if
document.createElement('optgroup')
magically returned a "HTMLOptGroupElement", but there is no expectation that
document.createElement(someExpression)
would do any type refinement.
This could break existing code like:
var element;
element = document.createElement('optgroup');
// do something with element as an HTMLOptGroupElement
// ...
element = document.createElement('div');
// do something with element as an HTMLDivElement
but I hope that such code is rare, and a simple variable rename is all that is required in any case.
Regards,
Tom