I am currently working on a function that dynamically updates the HTML aria-expanded
attribute based on whether it is true or false. However, when I declare element
as HTMLElement
, I encounter an error stating
Argument of type 'boolean' is not assignable to parameter of type 'string'
expandEotyDocumentsPanel(element: HTMLElement) {
this.eotyExpanded = !this.eotyExpanded;
element.setAttribute('aria-expanded', this.eotyExpanded);
}
It is important to note that this.eotyExpanded
is a boolean.
In relation to the second argument of setAttribute()
, guidance from the documentation available on MDN states:
A DOMString containing the value to assign to the attribute. Any non-string value specified is converted automatically into a string.
This led me to believe that providing a boolean value should be acceptable.
Is there a way for me to resolve this error?
Thank you.