Skip to content

'HTMLElement' is not defined when used in markup event handler #6643

@techniq

Description

@techniq

Describe 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

REPL

Logs

No response

System Info

See REPL

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcompilerChanges relating to the compilergood first issueA small, encapsulated issue, ideal for a new contributor to Svelte to tackle.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions