Weird behavior with Generics + SvelteHTMLElement

#2271

Issue

Open
P
paoloricciuti
Jan 25, 2024, 7:06 PM

Describe the bug

I was creating an "isomorphic component" (basically where you pass as and it render the correct html element) and i started experimenting with the typings to get autocompletion. I come up with this which works fine

<script lang="ts" generics="T extends keyof HTMLElementTagNameMap">
    import type { SvelteHTMLElements } from 'svelte/elements';
    export let as: T;

    type $$Props = SvelteHTMLElements[T] & {
        as: T;
    };
</script>

the typecheck per se works fine but what is a bit iffy it's the autocompletion. You get autocomplete for every prop even the one that are not associated with the type T (for example you get autocomplete for type if you use spam for as). I tried the same generic function in the typescript playground and it works correctly.

https://github.com/sveltejs/language-tools/assets/26281609/1bfdc057-5cb0-42f2-b3b1-d1a0a9886dc8

https://github.com/sveltejs/language-tools/assets/26281609/403a5a65-8d27-4200-b28d-9d76d895fb9d

Reproduction

  1. go to this TS playground https://tsplay.dev/NB1Gpw
  2. verify that autocomplete works correctly
  3. paste the above code in a svelte component in vscode
  4. try to import it and get autocompletion

Expected behaviour

You should only get autocompletion for the correct element

System Info

  • OS: Mac
  • IDE: VSCode

Which package is the issue about?

No response

Additional Information, eg. Screenshots

No response

Info

Assignees None
Labels upstream
Milestone None