Typescript: HTMLOptionElement gives error Property 'value' does not exist on type 'Element'.

Created on 6 Apr 2017  路  5Comments  路  Source: microsoft/TypeScript

I'm getting this in this case of an HTMLOptionElement value

image

It should have that value as HTMLOptionsCollection contains HTMLOptionElement elements:
readonly options: HTMLOptionsCollection;

interface HTMLOptionsCollection extends HTMLCollectionOf<HTMLOptionElement> {
    length: number;
    selectedIndex: number;
    add(element: HTMLOptionElement | HTMLOptGroupElement, before?: HTMLElement | number): void;
    remove(index: number): void;
}

Using [email protected]

My workaround was to use an unnecessary cast
let newValue = (target.options[newSelectedIndex] as HTMLOptionElement).value

Bug lib.d.ts help wanted

Most helpful comment

Please fix!

All 5 comments

Probably this is because the indexer of HTMLCollectionOf only returns Element, not HTMLOptionElement.

The generic should return type of T right?

That's right.

Please fix!

That would be awesome!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

blendsdk picture blendsdk  路  3Comments

wmaurer picture wmaurer  路  3Comments

weswigham picture weswigham  路  3Comments

bgrieder picture bgrieder  路  3Comments

uber5001 picture uber5001  路  3Comments