How to make inline snippets with JSdocs less verbose? #15865
-
I have this snippet for example that if I want to type becomes extremely verbose, because you have to add @type to each parameter, I can just transform it into a component instead, but the snippet is quite short: {#snippet MarketCell(
/** @type {string} */ label,
/** @type {string} */ value,
/** @type {number} */ hiddenVariants,
/** @type {number} */ hiddenProducts,
/** @type {number|undefined} */ index,
/** @type {boolean|undefined} */ primary,
/** @type {boolean|undefined} */ global,
)}
...
{/snippet} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Since rest arguments are currently not supported, alternatives are limited. If you collect the arguments into an options object, you can reduce it to one type definition, but the {#snippet MarketCell(
/** @type {{
label: string,
value: string,
hiddenVariants: number,
hiddenProducts: number,
index: number | undefined,
primary: boolean | undefined,
global: boolean | undefined,
}} */ options
)}
...
{/snippet}
{@render MarketCell({
label: 'a',
value: 'b',
hiddenVariants: 1,
// ...
})} As an alternative to rest args, you could use a single tuple argument, but editor tooling when writing {#snippet MarketCell(
/** @type {[
label: string,
value: string,
hiddenVariants: number,
hiddenProducts: number,
index: number | undefined,
primary: boolean | undefined,
global: boolean | undefined,
]} */ options
)}
...
{/snippet}
{@render MarketCell(['a', 'b', 1, /* ... */])} Footnotes
|
Beta Was this translation helpful? Give feedback.
Since rest arguments are currently not supported, alternatives are limited.
If you collect the arguments into an options object, you can reduce it to one type definition, but the
@render
code will become longer since all properties have to be named.As an alternative to rest args, you could use a single tuple argument, but editor tooling when writ…