How to make inline snippets with JSdocs less verbose? #15865
Answered
by
brunnerh
daviareias
asked this question in
Q&A
|
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} |
Answered by
brunnerh
May 6, 2025
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
|
0 replies
Answer selected by
daviareias
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to 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
@rendercode will become longer since all properties have to be named.{#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 writ…