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

Support new svelte $$Generic type #127

Closed
SomaticIT opened this issue Sep 7, 2021 · 3 comments · Fixed by #131
Closed

Support new svelte $$Generic type #127

SomaticIT opened this issue Sep 7, 2021 · 3 comments · Fixed by #131

Comments

@SomaticIT
Copy link
Contributor

Hello,

A couple of months ago (July 2021), the Svelte team added the ability to specify generics types when using TypeScript.

RFC: sveltejs/rfcs#38
Thread: sveltejs/language-tools#442

Exemple

<!-- ForEach.svelte -->
<script lang="ts">
  type T = $$Generic;
  export let items: T[];
</script>

{#each items as item}
  <slot {item} />
{/each}

<!-- App.svelte -->
<script lang="ts">
  import ForEach from "$lib/components/ForEach.svelte";
  import type { Todo } from "$lib/todo.service";

  let todos: Todo[] = [];
</script>

<ForEach items={todos} let:item>
  <!-- item is correctly typed as Todo here -->
  <p>{item.name}</p>
</ForEach>

Issue

When using this new feature, eslint-plugin-svelte3 complains with error no-undef.

Workaround

Disabling the error manually:

<script lang="ts">
  type T = $$Generic; /* eslint-disable-line no-undef */
  export let items: T[];
</script>

{#each items as item}
  <slot {item} />
{/each}
@Conduitry
Copy link
Member

Your fix has been released as 3.2.1. Thank you!

@SomaticIT
Copy link
Contributor Author

Happy to help! Thank you

@wvhulle
Copy link

wvhulle commented May 12, 2023

So this feature has been removed in the successor of the parser. Is it a good idea to revert to this version while it is not reimplemented yet?

sveltejs/svelte-eslint-parser#306

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants