Skip to content

<svelte:element> parameter has an 'any' type with an inline handler #2003

@AlbertMarashi

Description

@AlbertMarashi

Edit: I have hidden the old issue that was solved, but this thread contained two issues

Old issue

Describe the bug

Getting a typescript issue where <svelte:element> is erroring when I use href attribute on an element that may either be an anchor link or a div.

Object literal may only specify known properties, and '"href"' does not exist in type 'HTMLAttributes<any>'.

image

This causes no actual compilation errors, but it does appear as an error in the IDE which is annoying

Reproduction

https://github.com/AlbertMarashi/element-bug-1

Logs

No response

System Info

System:
    OS: macOS 12.6.2
    CPU: (8) arm64 Apple M1 Pro
    Memory: 88.88 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.17.0 - /usr/local/bin/node
    npm: 8.15.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 108.0.5359.124
    Firefox: 105.0.1
    Firefox Developer Edition: 109.0
    Safari: 15.6.1
  npmPackages:
    svelte: ^3.55.0 => 3.55.0

Severity

annoyance

I'm getting these issues with the e being untyped with svelte:elements

<svelte:element
    this={ unit ? "a" : "div" }
    class="paginator"
    class:active={ unit !== null }
    class:next={ direction === "next" }
    href={unit ? `/courses/${course.slug}/${unit.unit_slug}` : undefined}
    on:click={ pressed }
    on:keyup={ e => e.key === "Enter" && pressed() }>
...

Parameter 'e' implicitly has an 'any' type

#2003 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions