-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Indexing into a select .options attribute doesn't return an HTMLOptionElement #14522
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
Comments
It looks like it's getting the type from HTMLCollectionBase: https://github.com/Microsoft/TypeScript/blob/3e5b232e8816ff1af8b9ca2c04cee634ee86dc25/lib/lib.dom.d.ts#L4363 |
(For whoever may be reading this...) A work around for now is to use |
@RyanCavanaugh looking at the blame for lib.dom.d.ts, it looks like it used to have that and an update to it lost it. When we updated Google to TS 2.2 we had to work around foo[i] with foo.item(i) in a bunch of places. |
My example above now seems to work - I think this can be closed, at least for the select element. I'm not sure if other HTMLCollectionOf things work, since the change mentioned above has not been done. |
TypeScript Version: 2.2.1
Code
(http://www.typescriptlang.org/play/#src=let%20x%20%3D%20document.createElement('select')%3B%0D%0Ax.appendChild(document.createElement('option'))%3B%0D%0A%0D%0Alet%20z%20%3D%20x.options%5B0%5D%3B%0D%0A%2F%2F%20Error%2C%20z%20is%20an%20Element%2C%20not%20an%20HTMLOptionElement%0D%0Alet%20value%20%3D%20z.value%3B%0D%0A)
Expected behavior:
z
should be typed as anHTMLOptionElement
, allowing access to a.value
property.Actual behavior:
z is typed as an
Element
I think this error was exposed when I moved my code from TS 2.1 to 2.2.
The text was updated successfully, but these errors were encountered: