Skip to content

Commit

Permalink
fix: generic type annotation for snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
paoloricciuti committed Jun 22, 2024
1 parent 3cfaf1c commit 37c5e5c
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/svelte2tsx/src/htmlxtojsx_v2/nodes/SnippetBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,23 @@ export function handleSnippet(
let generic = '';
if (snippetBlock.parameters?.length) {
generic = `<[${snippetBlock.parameters
.map((p) =>
p.typeAnnotation?.typeAnnotation
.map((p) => {
let type_annotation = p.typeAnnotation;
if (!type_annotation && p.type === 'AssignmentPattern') {
type_annotation = p.left?.typeAnnotation;
if (!type_annotation) {
type_annotation = p.right?.typeAnnotation;
}
}
if (!type_annotation) return 'any';
return type_annotation.typeAnnotation
? str.original.slice(
p.typeAnnotation.typeAnnotation.start,
p.typeAnnotation.typeAnnotation.end
type_annotation.typeAnnotation.start,
type_annotation.typeAnnotation.end
)
: // slap any on to it to silence "implicit any" errors; JSDoc people can't add types to snippets
'any'
)
'any';
})
.join(', ')}]>`;
}

Expand Down

0 comments on commit 37c5e5c

Please sign in to comment.