I have a function which dynamically updates a HTML aria-expanded
attribute to true or false. However when I type element
as HTMLElement
, I receive a 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);
}
As you might have already noticed, this.eotyExpanded
is a boolean.
With regards to the second argument of setAttribute()
, the docs on MDN say:
A DOMString containing the value to assign to the attribute. Any non-string value specified is converted automatically into a string.
So I thought supplying a boolean value would be fine.
How can I suppress this error?
Thanks.
元素的属性不能是布尔值,所以你可能只是把它变成字符串而不是
new Boolean(this.eotyExpanded).toString()
I have a function which dynamically updates a HTML aria-expanded
attribute to true or false. However when I type element
as HTMLElement
, I receive a 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);
}
As you might have already noticed, this.eotyExpanded
is a boolean.
With regards to the second argument of setAttribute()
, the docs on MDN say:
A DOMString containing the value to assign to the attribute. Any non-string value specified is converted automatically into a string.
So I thought supplying a boolean value would be fine.
How can I suppress this error?
Thanks.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.