-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Select .options attribute should be an HTMLOptionsCollection #9334
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
HTMLOptionsCollection
doesn't recognize elements of HTMLOptionElement
s
I am not sure i understand why this changed but, 9a55fac should show the fixed definition. |
should be in typescript@next later tonight. |
I am a bit confused: from https://www.w3.org/TR/2011/WD-html5-20110525/common-dom-interfaces.html#htmloptionscollection-0 interface HTMLOptionsCollection : HTMLCollection {
// inherits item()
attribute unsigned long length; // overrides inherited length
caller getter object namedItem(in DOMString name); // overrides inherited namedItem()
void add(in HTMLElement element, in optional HTMLElement before);
void add(in HTMLElement element, in long before);
void remove(in long index);
attribute long selectedIndex;
}; from lib.d.ts: interface HTMLOptionsCollection extends HTMLCollectionOf<HTMLOptionElement> {
length: number;
selectedIndex: number;
add(element: HTMLOptionElement | HTMLOptGroupElement, before?: HTMLElement | number): void;
remove(index: number): void;
} and both has |
You're right! My mistake. Should HTMLOptionsCollection extend |
Thanks for the fast response on this! |
Can you explain why you think it should be a union? |
I suppose it is because both types are valid elements in the collection, but neither is declared as a subtype of the other. Actually, the instance side of both types is identical, but this is not clear from reading their definitions. var x: HTMLOptGroupElement;
var y: HTMLOptionElement = x;
x = y; is perfectly valid, but they are not explicitly related. A union would be clearer, but it would not affect typing. |
TypeScript Version:
1.9.0-dev (commit be6c34f)
Description
In https://github.com/Microsoft/TypeScript/blob/be6c34f1c79ec998c56ae127e572ffa9d7794b51/lib/lib.dom.d.ts#L6797,
.options
should be an HTMLOptionsCollection, which would have typed add/remove methods. We have an HTMLOptionsCollection defined at https://github.com/Microsoft/TypeScript/blob/be6c34f1c79ec998c56ae127e572ffa9d7794b51/lib/lib.dom.d.ts#L6633, but I think it should probably inherit fromHTMLCollectionOf<HTMLOptionElement>
(possibly unioned with an optgroup type too) for the typed index accessors, etc.Also, HTMLOptionsCollection shouldn't have a
selectedIndex: number;
attribute according to the spec at https://www.w3.org/TR/2011/WD-html5-20110525/common-dom-interfaces.html#htmloptionscollection-0Code
cf. #8220
The text was updated successfully, but these errors were encountered: