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

Svelte types not automatically inferred in .ts & .js files #4577

Open
1 task done
probablykasper opened this issue Jul 28, 2023 · 14 comments
Open
1 task done

Svelte types not automatically inferred in .ts & .js files #4577

probablykasper opened this issue Jul 28, 2023 · 14 comments
Labels
bug [core label] language An umbrella label for all programming languages syntax behaviors svelte Svelte framework support

Comments

@probablykasper
Copy link

probablykasper commented Jul 28, 2023

Check for existing issues

  • Completed

Describe the bug / provide steps to reproduce it

In SvelteKit projects, types are automatically inferred for many exported values (Zero-effort type safety).

In +page.svelte, it works:
image

But in .ts/.js files it does not:
image

Reproduce

  • Run npm create svelte@latest
  • Choose SvelteKit demo app
  • Check src/routes/sverdle/+page.server.ts (or .js)

Environment

Zed: v0.96.3 (stable)
OS: macOS 13.5.0
Memory: 32 GiB
Architecture: x86_64

@probablykasper probablykasper changed the title Svelte "Zero-effort type safety" not working in .ts files Svelte types not automatically inferred in .ts & .js files Jul 28, 2023
@JosephTLyons JosephTLyons added language An umbrella label for all programming languages syntax behaviors svelte Svelte framework support and removed triage labels Jul 28, 2023
@mikayla-maki
Copy link
Contributor

Duplicate of #4598

@probablykasper
Copy link
Author

@mikayla-maki I don't think this is a duplicate, unless you mean they have the same root cause. That issue seems to be about types not updating when importing in .svelte from a different file, while this issue is about types not being applied in JS/TS files

@mikayla-maki
Copy link
Contributor

Fair point, I misread.

@mikayla-maki mikayla-maki reopened this Jul 29, 2023
@ChristianPerez34
Copy link

ChristianPerez34 commented Oct 3, 2023

I am experiencing the same issues as @probablykasper

image

@ChristianPerez34
Copy link

This fixed issues for me Zed Documentation TypeScript

image

@JosephTLyons JosephTLyons transferred this issue from zed-industries/community Jan 24, 2024
@joshiain
Copy link

joshiain commented Feb 6, 2024

Installing typescript-svelte-plugin to my project got this working for me:

https://github.com/sveltejs/language-tools/tree/master/packages/typescript-plugin#usage

Would be nice if this wasn't needed though.

@chrisbrown-io
Copy link

@joshiain - any further info on how you set this up? I've installed typescript-svelte-plugin in my sveltekit project and added to my root tsconfig.json, yet zed still can't seem to pick up the generated types.

{
  "extends": "./.svelte-kit/tsconfig.json",
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-svelte-plugin",
        "enable": true,
        "assumeIsSvelteProject": false
      }
    ],
    ...

@chrisbrown-io
Copy link

chrisbrown-io commented Jul 11, 2024

Figured out why installing the plugin wasn't helping things. The change in Zed 0.141.2 to use vtsls as the default language server for typescript instead of typescript-language-server was causing issues with picking up the plugin.

I swapped back to using typescript-language-server and all of the functionality from typescript-svelte-plugin now functions correctly.

 "languages": {
    "JavaScript": {
      "language_servers": ["!vtsls", "typescript-language-server", "..."]
    },
    "TypeScript": {
      "language_servers": ["!vtsls", "typescript-language-server", "..."]
    }
    ...
  }

I have a hunch that vtsls might be trying to resolve the typescript-svelte-plugin relative to the location of it's tsserver? I couldn't get an appropriate configuration working passing custom lsp options via zed settings, so I gave up and just swapped to using typescript-language-server.

@Gioppix

This comment has been minimized.

@AlbertMarashi
Copy link
Contributor

AlbertMarashi commented Aug 30, 2024

To anyone unclear, until this is fixed, a temporary work around is to go to your tsconfig.json

And inside of compilerOptions paste the following

"plugins": [{
   "name": "typescript-svelte-plugin",
   "enabled": true,
   "assumeIsSvelteProject": false
}]

Run npm i typescript-svelte-plugin

And your SvelteKit types should start working (you may need to reload the extensions/restart the language servers)

@AlbertMarashi
Copy link
Contributor

AlbertMarashi commented Sep 9, 2024

Context

  • Svelte's VSCode extension uses the typescript LSP configurePlugin command to register the typescript-svelte-plugin
  • We don't appear to have a way to execute LSP commands within extensions
  • Users are experiencing a mismatch of behavior between VSCode and Zed.
  • Workaround: manually installing typescript-server-plugin and adding it into tsconfig.json -> compilerOptions.plugins

Questions

  • Is it possible to execute an LSP command for the typescript server from the svelte extension?
  • If not, are there other ways to enable a tsserver plugin without having to have users manually edit their tsconfig.json

Copy link

Hi there! 👋
We're working to clean up our issue tracker by closing older issues that might not be relevant anymore. If you are able to reproduce this issue in the latest version of Zed, please let us know by commenting on this issue, and we will keep it open. If you can't reproduce it, feel free to close the issue yourself. Otherwise, we'll close it in 7 days.
Thanks for your help!

@github-actions github-actions bot added the stale Label used by `stale` action label Jan 28, 2025
@probablykasper
Copy link
Author

Still reproducible in 0.170.4

@samausir
Copy link

Same here, and the workarounds mentioned above do not work for me. Changing the language server to typescript-language-server make matters even worse, because it seems to not recognize ESLint rule overrides in flat config.

@github-actions github-actions bot removed the stale Label used by `stale` action label Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug [core label] language An umbrella label for all programming languages syntax behaviors svelte Svelte framework support
Projects
None yet
Development

No branches or pull requests

9 participants