TypeScript-DOM-lib-generator icon indicating copy to clipboard operation
TypeScript-DOM-lib-generator copied to clipboard

HTMLFormControlsCollection namedItem should return only form input elements

Open matthieusieben opened this issue 5 years ago • 0 comments

TypeScript Version: 3.9.2

Search Terms: HTMLFormControlsCollection RadioNodeList namedItem

Code

declare const form: HTMLFormElement;

const element = form.elements.namedItem('foo')

if (element && !(element instanceof RadioNodeList)) {
  console.log('eee', element.value) // <<< Property 'value' does not exist on type 'Element'
}

Expected behavior: According to MDN, namedItem() on a HTMLFormControlsCollection only returns a specific set of element types.

Something like this: https://github.com/microsoft/TypeScript/pull/39004/files (though HTMLFormControlsCollection might need to extend HTMLCollectionOf<...> instead of HTMLCollectionBase)

Actual behavior: HTMLFormControlsCollection.namedItem() return type is not specific enough (Element).

Playground Link: https://www.typescriptlang.org/play/?ssl=7&ssc=2&pln=1&pc=1#code/CYUwxgNghgTiAEYD2A7AzgF3gMyTAtgFzwASAKgLIAyAYnvgKIQj4goYDcAUF8uliGat28ALw56AOkEs2GNJJRRWwAJIYWACgDkuJNoCUPAJbZ4mmcKwAya-ACEFoXPjH+UFGBBIzAJSjAxkgAckigVMaYBgbwAN5c8IioaEjMkhBIAOY6ILnaADTwlnKSAG5QEACuIEYAvlxAA

Related Issues: https://github.com/microsoft/TypeScript/issues/19437 https://github.com/microsoft/TypeScript/issues/39003

matthieusieben avatar Jun 10 '20 08:06 matthieusieben