tomblachut / svelte-intellij

Svelte components in WebStorm and friends
MIT License
485 stars 38 forks source link

Store autosubscription type inference suddenly stopped working #182

Closed JakubKoralewski closed 3 years ago

JakubKoralewski commented 3 years ago

My import:

//index.svelte
import {interfaceStore} from "../store/store";

Where $interfaceStore has type of Writable<MyStoreType> (according to IntelliJ's IntelliSense).

//store/store.ts
export const interface = ...

According to intellisense it is Writable<MyStoreType>.

The project itself builds fine. I tried invalidating cache and restarting but it didn't help. It's one of those problems that's hard to make a repro for since it'll probably work for you.

Is there anything I can check to make sure there isn't some simple reason for this? EDIT: versions: Svelte-intellij 0.15.2 WebStorm 2020.2.3 Build #WS-202.7660.23, built on September 30, 2020 Registry: editor.distraction.free.mode=true, eslint.additional.file.extensions=svelte Non-Bundled Plugins: AceJump, IdeaVIM, org.jetbrains.IdeaVim-EasyMotion, org.toml.lang, dev.blachut.svelte.lang

EDIT2: The way the error actually presents itself is in a method call which expects MyStoreType as a parameter, but when I pass in $interfaceStore the error says that Argument type Writable<MyStoreType> is not assignable to parameter type MyStoreType. I wanted to add this detail because the Intellisense I mentioned probably looked at the import and showed me interfaceStore's type and not $interfaceStore's type...

tomblachut commented 3 years ago

Please:

  1. show declaration of interfaceStore, ypu only showed interface. Also full declaration ofinterface would be helpful
  2. You are using TS in Svelte scripts, right?

I know about some problems for stores defined in Svelte files but your case seems different, IDK what's happening for now.

JakubKoralewski commented 3 years ago
  1. Sorry about that.

That was a mistake. It should have been export interfaceStore: Writable<MyStoreType> = .... I won't edit the comment for posterity. I really think there's no point to showing the declaration of interfaceStore. It's just an object and this autosubscription type inference worked really well for a good while for me with this same object, I don't know what is happening either. If you insist I created a simplified gist here.

I found a more direct issue. The interfaceStore import inside index.svelte only had the type of Writable<MyStoreType> because I annotated that type on export in store.ts: export const interfaceStore: Writable<MyStoreType> = ....

If I remove this type annotation: export const interfaceStore = ... it turns out this type is actually any. (It's actually now correct). Looking into the type of function writable that is imported at the very top of store.ts it has the type of import writable. So it has lost its actual type information. initial value is any

the above is inside a typescript file mind you, but the below is in the same file (store.ts) and still it has type for the return value (!?) obraz

Go to declaration functionality still works on writable, but for some reason the type information is gone, if I'm correct? If I normally import a function it has a dark yellow sort of color, but this looks totally white.

Check this, valid import: obraz

This import as compared to the below (IInterfaceStore is an interface): obraz

I also tried importing my interface from a typescript file. It works correctly and shows the right type without me having to annotate it. Only inside svelte files the type of the imported interfaceStore is any, and so is $interfaceStore.

I tried invalidating and restarting multiple times.

  1. Yes.

Thanks for your time. I think this could be some simple/weird problem possibly unrelated to Svelte-intellij, since it worked before as expected.

Looks like I have even trouble with permissions when deleting node_modules. Spooky. Maybe a good old restart will help. It didn't.

tomblachut commented 3 years ago

I don't know what's happening, sorry. I've pasted your gists into TS project and everything seems to be working. image

You may try to reproduce your issues in freshly setup project, IDK.

tomblachut commented 3 years ago

Closing for now, please reach out if still experiencing issues.