-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getElementById inconsistent between TS and Closure #163
Comments
To repro this in a test: let foo = document.getElementById('foo'); it produces let /** @type {HTMLElement} */ foo = document.getElementById('foo'); |
Note that you can't work around this with coercions because of bugs like microsoft/TypeScript#6982 where comments are dropped. let foo = <Element>document.getElementById('foo'); becomes let /** @type {Element} */ foo = /** @type {Element} */(( <Element>document.getElementById('foo'))); becomes let /** @type {Element} */ foo = (document.getElementById('foo')); And see that "Element" was dropped. |
Shouldn't we initially disable type checking within the TypeScript file?
It's nice to have checking for code depending on it, but we don't need the
check in the file – TS has already type checked that, right?
|
In theory we're relying on types for optimization, so I'm not sure what it means if we disable type checking. Like if you write let foo = document.getElementById('foo');
foo.barField; where "barField" is in HTMLElement but not Element, I'm not sure what the Closure optimizer will do to |
My unchecked understanding is that Closure Compiler will rename properties With it on, it's unclear, there's some stuff in Closure Compiler where it's |
We suppressed checkTypes. |
document.getElementById returns an
Element
in Closure and anHTMLElement
in TS. (Element
is the supertype; SVG elements are a sibling to HTML elements.) This leads to compilation problems like:microsoft/TypeScript#3263 (comment) says: "However, in the case of getElementById, we made it convenient by returning HTMLElement by default, although it is different from the spec." Sadness.
It looks like they might change something in this area in microsoft/TypeScript#4689 .
See also #42 . This is maybe an argument for using our own modified standard library.
The text was updated successfully, but these errors were encountered: