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
Svelte5 JSDoc for $props
#10541
Comments
You can use typedef for this: /**
* @typedef Props
* @property {number} count Some documentation
*/
/** @type {Props} */
let { count } = $props(); Giving this the documentation label to note this wherever in the final new docs we're going to talk about typing stuff. |
@dummdidumm this does not seem to work at the moment. If I do a |
Look at the last comment before the node first, check for `@type` and prevent `@typedef` false positive sveltejs/svelte#10541 (comment)
Look at the last comment before the node first, check for `@type` and prevent `@typedef` false positive sveltejs/svelte#10541 (comment)
@dreitzner It does work: Nonetheless the error occurs in different IDE's and is definitely a bug. There are more options though:
2.a. Define the type in a separate definition file:
2.b. Though in most cases it would probably be more useful to make the definition file a module:
|
The code I gave is correct, there's a bug in the VS Code Svelte extension which I fixed in sveltejs/language-tools#2294, release pending. |
@dummdidumm thank you so much for the explenation and the fix :) |
The <script>
/**
* @param {Object} Props
* @param {string} Props.name
*/
let { name, age, date } = $props()
</script>
<p>Your {name}</p>
<!-- ^ type is `unknown` --> Can we allow this method of documentation and typing? It could save a couple of lines. It seems to work with plain JS: playground. |
That's invalid syntax, the types just come from inference based on the assigned value. You can do something like this: /**
* @type {{
* name: string,
* age: number,
* ...
* }}
*/
let { name, age, date } = $props() |
Thanks for educating me; I don't know why I thought I was hoping |
Describe the problem
When declaring props with TS, we can add JSDoc comments and type annotations:
This will show all the info also in intellisense when the component is used:
But when not using TS, I don't think there is a way to pass that extra info to the LSP.
Describe the proposed solution
It might be nice to add the possibility to augment the destructured props like this:
There might be already a working solution out there, that I'm not aware of....
In that case I'd be happy to add it to the docs :)
Importance
nice to have
The text was updated successfully, but these errors were encountered: