Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot import TS types from Svelte components in .svelte.ts files #14884

Open
Bilge opened this issue Jan 3, 2025 · 6 comments
Open

Cannot import TS types from Svelte components in .svelte.ts files #14884

Bilge opened this issue Jan 3, 2025 · 6 comments

Comments

@Bilge
Copy link

Bilge commented Jan 3, 2025

Describe the bug

I cannot import types exported in a <script module lang="ts"> block in a .svelte.ts file (I can import them in other .svelte files).

TS complains that:

TS2614: Module '".svelte"' has no exported member 'ListRecord'. Did you mean to use 'import ListRecord from ".svelte"' instead?

Indeed, importing from "*.svelte" does actually work, but my editor thinks it's an error (and it sure does look wrong).

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-umuyfhqp?file=src%2Froutes%2FOtherTest.svelte.ts

Logs

No response

System Info

System:
    OS: Linux 5.15 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
    Memory: 7.56 GB / 11.69 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 22.12.0 - /run/user/1000/fnm_multishells/1080_1735405309856/bin/node
    Yarn: 1.22.22 - /run/user/1000/fnm_multishells/1080_1735405309856/bin/yarn
    npm: 10.9.0 - /run/user/1000/fnm_multishells/1080_1735405309856/bin/npm
  npmPackages:
    svelte: ^5.0.0 => 5.15.0
    webpack: ^5.11.0 => 5.97.1

Severity

blocking all usage of svelte

@Ocean-OS
Copy link
Contributor

Ocean-OS commented Jan 3, 2025

This is probably some sort of compiler issue, since typescript AST nodes are removed during compilation, and Svelte IDE tools usually compile the component as a part of their process.

@paoloricciuti
Copy link
Member

Mmm i feel like this is probably in @dominikg territory...can you confirm if it's something to fix in vite-plugin-svelte?

@Bilge
Copy link
Author

Bilge commented Jan 3, 2025

FWIW I'm using Webpack, so if it is, it needs fixing in svelte-loader also.

@paoloricciuti
Copy link
Member

FWIW I'm using Webpack, so if it is, it needs fixing in svelte-loader also.

Uhm then maybe it's not will try to take a look

@dummdidumm
Copy link
Member

This is not a runtime / bundler issue. This has to do with language tools. Your editor does not seem to use the typescript plugin - what IDE are you using?

@dominikg
Copy link
Member

dominikg commented Jan 4, 2025

as a workaround or maybe even a better practice, export the type from a separate types.ts file?

whats the usecase for exporting a type there? component props are the only ones i can think of rn but they should work without export

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants