Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Svelte 5 generics #583

Open
marekdedic opened this issue Nov 8, 2024 · 4 comments · May be fixed by #589
Open

Add support for Svelte 5 generics #583

marekdedic opened this issue Nov 8, 2024 · 4 comments · May be fixed by #589
Labels
enhancement New feature or request

Comments

@marekdedic
Copy link
Contributor

Description

Hi,
generics are now officially part of Svelte 5. However, it seems to me that this parsers doesn't support them:

<script generics="KeyType extends number | string, ValueType" lang="ts">
  import type { Snippet } from "svelte";

  interface Props {
    children?: Snippet<[KeyType, ValueType]>;
    options: Array<[KeyType, ValueType]>;
    selected: Array<KeyType>;
  }

  let { children, options, selected = $bindable() }: Props = $props();

  selected;
</script>

{#each options as [id, value] (id)}
  <label>
    <input type="checkbox" value={id} bind:group={selected} />
    <span></span>
    {@render children?.(id, value)}
  </label>
{/each}

Gives 'ValueType' is not defined and similar

I tried to create a repro, but the playground is stuck at "Starting WebContainer"...

@marekdedic marekdedic added the enhancement New feature or request label Nov 8, 2024
@ota-meshi
Copy link
Member

I wasn't aware that generics were now an official feature 👀
For now it works fine if you enable it in the parser configuration.

See https://github.com/sveltejs/svelte-eslint-parser?tab=readme-ov-file#parseroptionssveltefeatures

      parserOptions: {
        // ...
        svelteFeatures: {
          experimentalGenerics: true,
        }
      },

@ota-meshi
Copy link
Member

I tried to create a repro, but the playground is stuck at "Starting WebContainer"...

That link works fine on my local computer, I don't know what the problem is...

@marekdedic
Copy link
Contributor Author

Great, I enabled the config and it works, thanks! They're official, so maybe it's time to stabilize them here as well :)

@ota-meshi
Copy link
Member

ota-meshi commented Nov 16, 2024

Well, the RFC hasn't been merged yet, but it's in the official documentation so we can probably consider it an official feature.

They're official, so maybe it's time to stabilize them here as well :)

I think so 👍

@marekdedic marekdedic linked a pull request Nov 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants