svelte-eslint-parser icon indicating copy to clipboard operation
svelte-eslint-parser copied to clipboard

Extract slot prop types from `$$Slots`

Open marekdedic opened this issue 1 year ago • 1 comments

Description

In ota-meshi/eslint-plugin-svelte#347 I proposed a rule to require slots and their props to be typed. In this package, those types should be used if they're present.

An example of what currently doesn't work:

App.svelte:

<Component let:arrayProp={arrayValue}>
  {#each arrayValue.filter( (val) => val.length > 10 ) as val} <!-- HERE -->
    {val}
  {/each}
</Component>

Component.svelte:

<script lang="ts">
  interface $$Slots {
    default: { arrayProp: Array<string> };
  }
</script>

<slot arrayProp={["Hello", "World", "Hello World"]} />

Here, on the marked line, I get the eslint error @typescript-eslint/no-unsafe-call - I presume that's because the parser does not infer that arrayValue is of type Array<string> and leaves it as any...

marekdedic avatar Feb 06 '23 12:02 marekdedic