tomblachut / svelte-intellij

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

Reference to `./$types` does not work in .svelte files but works in .ts files #309

Closed martinbeentjes closed 2 years ago

martinbeentjes commented 2 years ago

When importing a SvelteKit type (e.g. PageData) in a .svelte file, the IDE thinks it does not know $types. When importing a SvelteKit type (e.g. PageServerLoad) from a .ts file, it does work properly.

Schermafbeelding 2022-08-30 om 14 41 54

Schermafbeelding 2022-08-30 om 14 42 05


Edit [30th of August]: I have rephrased the issue to the issue I am actually facing. Text below was original text

I am upgrading one of my projects to the newest version SvelteKit. I am seeing some errors in my code which are not errors. So an error inside Webstorm and the Svelte plugin.

Since the new router changes to SvelteKit, there are some errors in the plugin. For example, the following error. Module '"./$types"' has no exported member 'Load'. This happens on an import type { Load } from './$types';

How can I assist in fixing these? Where do I start?

MFerraz commented 2 years ago

These files are generated automatically on the .svelte-kit/types folder as part of the npm lifecycle. I believe you can force them to be generated using npx svelte-kit sync (docs). I believe this may solve your issue.

However, after they are generated, I'm getting another issue on svelte files when trying to import ./$types - Cannot resolve file '$types'

It is working on VSCode, and it is also working when the import is on a Typescript file. The error only shows on the script tag of svelte files when running WebStorm

martinbeentjes commented 2 years ago

I'll adapt this issue, I was indeed making a mistake myself. However, I am having the same issue as you, with ./$types unknown.

One to investigate, I am also having some issues with duplicate code. But that was fixed by marking the .svelte-kit folder excluded.

bhvngt commented 2 years ago

I was facing similar issues. I changed my tsconfig.json to include files from root dir. That seems to have fixed the import of ./$types. However, in +page.svelte file, while it correctly imports PageData type, data variable still stays untyped.

Here's the screenshot of my setup.

image

martinbeentjes commented 2 years ago

Seems this is unrelated to the plugin, but a Webstorm issue.

dennisjlee commented 2 years ago

@martinbeentjes do you know if there is a separate issue we can follow for the underlying Jetbrains / Webstorm problem here?

martinbeentjes commented 2 years ago

https://youtrack.jetbrains.com/issue/WEB-57119/rootDirs-specified-in-tsconfigjson-not-respected-when-resolving-imports-in-svelte-files