javascript - How to work with form elements in typescript -


i'd access form elements via myform.elements, , access each element it's name, example, myform.elements.month. typescript doesn't b/c doesn't know form.elements contains property of month. thought, let's create interface! did, (see code below), i'm getting typescript error: neither type 'htmlcollection' nor type 'formelements' assignable other

here's code i'm working with:

interface formelements {     day: htmlinputelement;     month: htmlinputelement;     year: htmlinputelement; }  class birthdateinput {     constructor(form: htmlformelement) {         var elements: formelements = <formelements> form.elements; // error here          this.day = elements.day;         this.month = elements.month;         this.year = elements.year;     } } 

any ideas on how better cast form.elements object typescript won't complain?

best way write this:

// note 'extends' clause here interface formelements extends htmlformelement {     day: htmlinputelement;     month: htmlinputelement;     year: htmlinputelement; }  class birthdateinput {     constructor(form: htmlformelement) {         var elements: formelements = <formelements> form.elements; // ok         // ...