'HTMLElement' is not defined when used in markup event handler
See original GitHub issueDescribe the bug
If HTMLElement is used in an event handler, for example:
<button on:click={e => { if (e.target instanceof HTMLElement) { } }}>Click me</button>
It produces the following unexpected warning:
‘HTMLElement’ is not defined. Consider adding a <script> block with ‘export let HTMLElement’ to declare a prop (5:49)
If you use Element
in the handler, no warning is produced:
<button on:click={e => { if (e.target instanceof Element) { } }}>Click me</button>
or if you pull the handler into a function within <script>
<script>
function onClick() {
if (e.target instanceof HTMLElement) {
}
}
</script>
<button on:click={onClick}>Click me</button>
Reproduction
Logs
No response
System Info
See REPL
Severity
annoyance
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:8 (4 by maintainers)
Top Results From Across the Web
ReferenceError: <function> is not defined at HTMLElement ...
I am trying to allow a user to input multiple tags and be able to remove them from the array by use of...
Read more >HTMLElement: input event - Web APIs | MDN
The input event fires when the value of an , , or element has been changed.
Read more >JavaScript Events - W3Schools
HTML events are "things" that happen to HTML elements. ... HTML allows event handler attributes, with JavaScript code, to be added to HTML...
Read more >DOM Elements - React
In React, all DOM properties and attributes (including event handlers) should ... In most cases, className should be used to reference classes defined...
Read more >Event handlers - HTML Standard, Edition for Web Developers
Event handlers, whether registered through the DOM using addEventListener() , by explicit event handler content attributes, by event handler IDL attributes, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
HTMLElement
andSVGElement
are both now marked as known globals in 3.42.2. Thanks @vicky1999!Hi, I would like to work on this issue. can I try it?