question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Assist with store imports with svelte $ prefix

See original GitHub issue

Description

Regarding the shortcut to directly access store values , https://svelte.dev/docs#component-format-script-4-prefix-stores-with-$-to-access-their-values

A pattern I’ve noticed which has become a sore point over and over is refactoring or writing new code which references a store with the $ prefix. For example, I might write or copy from one component to another…

{#if $showTheThing}

{/if}

However the import is missing so I will click somewhere on $showTheThing to do CTRL + . so that VSCode can import this from the store. This doesn’t provide the hint I want. All I get shown is “(svelte) Disable Missing Declaration for this line

So then I remove the $ from the string, then do CTRL + . again to import,

{#if showTheThing}

{/if}

Then go back to the beginning of the variable to prepend it back with $

{#if $showTheThing}

{/if}

Proposed solution

I would like to use CTRL + . on $showTheThing and have it suggest the correct import (or even multiple imports at once in the case that many imports are missing).

Alternatives

No response

Additional Information, eg. Screenshots

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
jasonlyu123commented, Dec 17, 2022

Guess your local build is still an old version. It did work before but we changed the way we transform the $store variable a while ago to fix some type-checking issues. You can run yarn bootstrap to update it.

0reactions
Jojoshuacommented, Dec 19, 2022

Alrighty, I just linked a PR for this, let me know what you think.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with Svelte stores - Learn web development | MDN
Svelte provides functions for creating readable, writable, and derived stores in the svelte/store module. Svelte also provides a very intuitive ...
Read more >
v4.9 broke accessing stores with $ prefix when imported in ...
Hey, everywhere in my code where I access store values using the $ prefix now cause an is not defined error similar to...
Read more >
Docs • Svelte
Prefix stores with $ to access their values​​ Any time you have a reference to a store, you can access its value inside...
Read more >
How to get store value from another store? - svelte
Just prefix the store name with $ , eg. const value = $myStore . Share.
Read more >
State Management with Svelte - Stores (Part 3) -- newline
import { writable } from 'svelte/store';. Then, call the writable function. It accepts the same two arguments ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found