question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeScript warning when using <svelte:element/> with sveltekit:prefetch attribute

See original GitHub issue

Describe the bug

I have a Button component that renders a dynamic tag using svelte:element. Sometimes it renders anchor tags, so I have applied sveltekit:prefetch to the element, but TypeScript complains that svelte:element doesn’t support that attribute. The attribute still works as expected: when an anchor tag is rendered, the sveltekit:prefetch attribute is present and triggers the desired prefetching behavior on hover. When a different tag (e.g. button) is rendered, the sveltekit:prefetch attribute is also present, but seems to have no adverse effect.

Is there a ‘valid’ way to use this attribute on this element? Should the type definition of svelte:element be expanded to allow this usage?

Reproduction

I have a REPL explaining the issue, and the use case behind it, here: https://svelte.dev/repl/bfbeb5c43f21461c9cbd0fea3cd680cb?version=3.49.0

Logs

No response

System Info

System:
    OS: macOS 12.5
    CPU: (10) arm64 Apple M1 Pro
    Memory: 107.34 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.15.1 - /usr/local/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 8.11.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 104.0.5112.79
    Firefox: 101.0.1
    Safari: 15.6
    Safari Technology Preview: 16.0
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.63 
    @sveltejs/kit: next => 1.0.0-next.393 
    svelte: ^3.44.0 => 3.49.0 
    vite: ^3.0.0 => 3.0.3

Severity

annoyance

Additional Information

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
dummdidummcommented, Aug 4, 2022

I’d say this is purely a TS error which in this case we should fix, we can’t know what svelte:element is so we should allow all attributes. Moving this to language-tools.

0reactions
dummdidummcommented, Aug 5, 2022

By “all attributes” I meant what you mean, all valid attributes of all elements + the special ones (that’s the problem here) 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using svelte:element with sveltekit:prefetch? • REPL • Svelte
TypeScript warning when applying sveltekit:prefetch to svelte:element. ... Property 'sveltekitPrefetch' does not exist on type '&lbrace; this: string | null ...
Read more >
Style tag lang attribute triggers warning from Svelte Beta #129
Describe the bug When specifying a lang attribute in component's. ... project by using: degit svelte/template-webpack; Install TypeScript, ...
Read more >
TypeScript support in Svelte - Learn web development
We will now learn how to use TypeScript in Svelte applications. First we'll learn what TypeScript is and what benefits it can bring...
Read more >
Svelte custom event on svelte typescript - Stack Overflow
I'm using clickOutside directive on my svelte-typescript project and I'm getting this ... Property 'onclick_outside' does not exist on type ...
Read more >
Why Typescript and Svelte are a match made in heaven
In this guide, we'll learn how TypeScript can make your Svelte apps more powerful, while adding confidence to the code you're putting in ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found