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

Bundled Svelte 4 types loaded in a Svelte 5 project and causing conflict #2493

Closed
jethrolarson opened this issue Sep 7, 2024 · 4 comments
Closed
Labels
Fixed Fixed in master branch. Pending production release.

Comments

@jethrolarson
Copy link

jethrolarson commented Sep 7, 2024

Describe the bug

See title and repro

Work around is to add the types to the callbacks manually but that skips typechecking so not ideal.

Reproduction

  import { writable, type Writable } from 'svelte/store';
...
  let _curMessage: string;
  const currentMessage = writable<string>('');
  currentMessage.subscribe((cur) => (_curMessage = cur));

image

node_modules/svelte/src/store/shared/index.js:

image

Logs

n/a vscode

System Info

osx apple m1 Sonoma

VSCode
Version: 1.90.1 (Universal)
Commit: 611f9bfce64f25108829dd295f54a6894e87339d
Date: 2024-06-11T21:02:41.372Z
Electron: 29.4.0
ElectronBuildId: 9593362
Chromium: 122.0.6261.156
Node.js: 20.9.0
V8: 12.2.281.27-electron.0
OS: Darwin arm64 22.1.0

Severity

annoyance

@jethrolarson
Copy link
Author

Strictly speaking, I don't know whether this is because of svelte or vscode or typescript. I just know it's a new problem after upgrading svelte

@jasonlyu123
Copy link
Member

This seems to be caused by the Svelte for VSCode extension. It seems to be because of the conflict between the Svelte 4 type definition bundled by the Svelte extension and the workspace Svelte 5 types. Interestingly the type no longer conflicts in TypeScript 5.5+ but not because of the support for the JSDoc template tag. The actual type loaded is still the hidden .d.ts file. What you see in go to definition is because of the declaration map. The reason is probably because TypeScript 5.5 got slightly smarter at choosing between overloads with very similar types.

@jasonlyu123 jasonlyu123 transferred this issue from sveltejs/svelte Sep 9, 2024
@jasonlyu123 jasonlyu123 changed the title Svelte 5 vscode typescript not able to follow jsdoc imports Bundled Svelte 4 types loaded in a Svelte 5 project and causing conflict Sep 9, 2024
@dummdidumm
Copy link
Member

@jasonlyu123 do you have an idea why our bundled types are loaded? Is it because of our d.ts files in svelte2tsx which reference Svelte imports? I always had the impression that those are pointing back to the user's Svelte version.

@jasonlyu123
Copy link
Member

It's like require.resolve('svelte', '/path/to/shims.d.ts') I think. Not sure if we can move the import to the generated code and pass it into the helper function as a parameter. Or if we could create a virtual module inside the user's node_modules to re-export from svelte.

dummdidumm added a commit that referenced this issue Nov 5, 2024
Since the global types now reference `svelte/...` imports, they need to be placed in the same context the users' Svelte package lives in. Else these imports would load the types of the Svelte version that comes bundled with the IDE.

#2493

(side note: we had this problem before, when loading `svelte/elements`, and solved it through #9070, but that solution is not applicable here)
dummdidumm added a commit that referenced this issue Nov 6, 2024
Since the global types now reference `svelte/...` imports, they need to be placed in the same context the users' Svelte package lives in. Else these imports would load the types of the Svelte version that comes bundled with the IDE.

#2493

(side note: we had this problem before in #2109 when loading `svelte/elements`, but that solution is not applicable here)
@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed Fixed in master branch. Pending production release.
Projects
None yet
Development

No branches or pull requests

3 participants