How to type $props in Svelte 5 with JSDoc? #11066
Answered
by
brunnerh
danielniccoli
asked this question in
Q&A
-
How do I move my JSDoc type annotations from /** @type {HTMLDialogElement} */
export let dialog
/** @type {string} */
export let title to let { dialog, title } = $props(); in an efficient way? The only working solution I found was this /**
* @typedef $props
* @type {object}
* @property {HTMLDialogElement} dialog - an ID.
* @property {string} title - your name.
*/
/** @type {$props} */
let { dialog, title } = $props() which is overly verbose, /** @type {{dialog: HTMLDialogElement, title: string}} */
let { dialog, title } = $props() which becomes unwieldy quickly, due to all of it being in one line. Something along the lines of the follow (which does not work) /**
* @param {HTMLDialogElement} dialog
* @param {string} title
*/
let { dialog, title } = $props() |
Beta Was this translation helpful? Give feedback.
Answered by
brunnerh
Apr 4, 2024
Replies: 1 comment
-
You can break /**
* @type {{
* dialog: HTMLDialogElement,
* title: string,
* }}
*/
let { dialog, title } = $props() |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
danielniccoli
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can break
@type
definitions over multiple lines, syntax highlighting might be a bit funky, depending on editor.