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 5: Cannot get $props types from component with children #10644

Closed
kuechlerm opened this issue Feb 26, 2024 · 9 comments
Closed

Svelte 5: Cannot get $props types from component with children #10644

kuechlerm opened this issue Feb 26, 2024 · 9 comments
Labels
awaiting submitter needs a reproduction, or clarification

Comments

@kuechlerm
Copy link

kuechlerm commented Feb 26, 2024

Describe the bug

For components without children I can simply use

import type { ComponentProps } from 'svelte';
import Component from './Component.svelte';
type Props = ComponentProps<Component>;

but for components with children I get this error:
Type 'default' does not satisfy the constraint 'SvelteComponent<any, any, any>'. Type 'default' is missing the following properties from type 'SvelteComponent<any, any, any>': $$prop_def, $$events_def, $$slot_def, $destroy, and 2 more.

Any tips how to fix that?

Reproduction

https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAE51SYWujQBD9K8MSMAGJ0PaTMbZ6f-Cg_XZ7FIljsqCzy86kJYj__Vi16bVNW-6-iDPP9-a9cXrVmBZZpb96RVWHKlWFcypWcnKh4CdsBVWs2B79LnQy3nnjBNqK9luthLXKNQGYzlkvEHjQww_bOUtI8tNbxzBA420H0SQXbTRpmQnFDK2TYn0BLs9w-TdMWpIE-GCfGdw4Igzm0B8dFI_T4O07J1mRb96Q5-IhkKIam-rYSgS1RQayAlyJ4eYEckDYWWLxlSGB6H60ctbOKjrF8PLIo3XYyEdZw9AZZkP7UbCxbWufQxUioBeDPMUdM3w3JIXFIhAfa2xiWCzwCUn4peLWyvxeI4u3I62GK-isx7Xw8ur65mZ13lj52cbKaWOasmT69XnYf1YkuaaszMssKXMVq87WpjFYq1T8EYf49Z7-_Zq0aGlRoIcKBtjCGJOzvkpZvKH9kC9Xm3eGiq88lP_j4e1F35NxDuXiKc9eY9gdTFt7pIuuX-HbdFa7FKS_80g1-vPXy9UQ-h_z_R7-ADUAlVG_AwAA

Logs

No response

System Info

5.0.0-next.68

Severity

annoyance

@dummdidumm
Copy link
Member

Please provide a proper reproduction (you can also use the REPL)

@dummdidumm dummdidumm added the awaiting submitter needs a reproduction, or clarification label Feb 27, 2024
@kuechlerm
Copy link
Author

Unsure how a REPL can help here, as it does not show the TS errors, but I added the REPL to the description above.

@dummdidumm
Copy link
Member

Thanks, I copied over the REPL into VS Code and I don't get said TypeScript errors. Make sure to update to the latest version of VS Code and Svelte. There were changes to snippets recently which needed adjustment in the VS Code extension. Please let me know if this fixes the issue.

@kuechlerm
Copy link
Author

kuechlerm commented Feb 29, 2024

I still have the same error. All versions should be the latest:

  • svelte 5.0.0-next.69
  • VS Code 1.87.0
  • VS Code Svelte Plugin (svelte.svelte-vscode) v108.3.1

I don't know, if this helps, but running svelte-kit sync && svelte-check --tsconfig ./tsconfig.json does not result in any errors.

@dummdidumm
Copy link
Member

It sounds like VS Code isn't finding your installed Svelte version and then resorts to using its own. If you search for the Svelte -> Language-Server -> Debug setting in the VS Code settings UI, check the box, restart the language server and wait until the diagnostic shows up, then open the Output tab and select "Svelte" from the dropdown, what's inside there? There should be some "Using Svelte v5.0.0-next.69 from xxxxx\svelte\compiler" messages in there, are they pointing to the correct location?

@kuechlerm
Copy link
Author

It logs Using Svelte v5.0.0-next.69 from /Users/xxx/node_modules/.pnpm/[email protected]/node_modules/svelte/compiler
and in Finder I can find a compiler.cjs at that location.

@dummdidumm
Copy link
Member

Is this snippet

import type { ComponentProps } from 'svelte';
import Component from './Component.svelte';
type Props = ComponentProps<Component>;

Inside a TypeScript (not a Svelte) file by any chance? If so, then this is a duplicate of sveltejs/language-tools#2297

@kuechlerm
Copy link
Author

Oh no - I did not think that there is was difference between svelte and ts files.
Yes, the snippet works as expected in a svelte file.
Should I close this?

@dummdidumm
Copy link
Member

Closing in favor of sveltejs/language-tools#2297 then 👍

@dummdidumm dummdidumm closed this as not planned Won't fix, can't repro, duplicate, stale Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting submitter needs a reproduction, or clarification
Projects
None yet
Development

No branches or pull requests

2 participants