-
-
Notifications
You must be signed in to change notification settings - Fork 202
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
Wrong svelte/elements
types loaded
#2109
Comments
Tough one. That also seems to be why we can't use declare module "svelte/elements" to enhance typing. The only solution I can think of is a virtual module that replaces the "svelte/elements" with a full file path to the user version. Maybe an actual file we just hide in the node_modules or a virtual file that only exists in the memory. It might also work if we use the same method we remove the "*.svelte" module declaration, but not sure if that work if monorepo. |
Another not-so-great option could be to rename the Svelte package when building language tools for the VS Code extension. But that means it does not work for others using it through the LSP.. I think your idea of a hidden file or a virtual file is the most promising solution. |
Another idea is to turn it around: Place this ambient file inside Svelte itself. This is basically what React etc do. This could have the added benefit that SvelteKit could enhance the typings independently, right now we have a forced relationship between all these parts, which this would resolve. For SvelteKit we could even spin it further and move the "these exports exist" logic currently within the TypeScript plugin and within svelte2tsx into SvelteKit by having some generic extension interface with language tools. |
Yeah. That seems like the ideal solution. For backwards compatibility, we can keep a copy of it and only load that if we can't detect a supported version. We can manually copy it or use a script to download the latest from the Svelte repo. And after we bump our bundled version to Svelte 4, we just manually load bundled version if not supported. |
Sounds great! Would you be willing to work on this or are you too busy the next few weeks? |
I can try it. BTW, Do you have any solution with #2003? It would probably be easier if we could fix it before moving it to the svelte core. The problem is that TypeScript can't infer the parameter type from the union. |
Looked into it, no idea right now how to best solve this - shouldn't block us though, it's an edge case and if we come up with a solution we can adjust both the Svelte typings and our fallback types. |
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)
Describe the bug
When
svelte-jsx(-v4).dts
doesimport('svelte/elements')
TypeScript resolves this to the Svelte typings of the language tools extension. But it should resolve it to the user's implementation instead.Reproduction
Replace the
svelte:options
entry insvelte-jsx-v4.d.ts
with'svelte:options': import('svelte/elements').SvelteHTMLElements['svelte:options'];
, then observe that in intellisense it still does not provide any type hints. Then click on the import and see that it directs you to the language tools' version of Svelte.Expected behaviour
Should use user's implementation
System Info
irrelevant
Which package is the issue about?
svelte-language-server
Additional Information, eg. Screenshots
@jasonlyu123 do you have any idea how we could make this work? At runtime we have
importPackage
, but we don't have that here.The text was updated successfully, but these errors were encountered: