Skip to content

svelte-language-server thinks it's error to use store value as array index #407

@egormalyutin

Description

@egormalyutin

Describe the bug
I have a component like this:

<script lang="ts">
  import Bar from "./Bar.svelte";
  import { writable } from "svelte/store";

  const currentTab = writable(0);
  const barIcons = ["telescope", "results", "results"];

  import Inputs from "./Inputs.svelte";
  const tabs = [Inputs];
</script>

<main>
  <Bar bind:current={$currentTab} icons={barIcons} />
  <svelte:component this={tabs[$currentTab]} />
</main>

svelte-language-server detects a TypeScript error in <svelte:component this={tabs[$currentTab]} />:

Cannot find name '$currentTab'. Did you mean 'currentTab'?

Although it compiles without any errors or warnings.

What's interesting, if I add "+ 0" or even "+" near $currentTab, svelte-language-server will detect no error.

  <svelte:component this={tabs[+$currentTab]} />

Expected behavior
No errors must be detected.

System (please complete the following information):

  • OS: Arch Linux
  • IDE: nvim with coc-svelte

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedFixed in master branch. Pending production release.bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions