Skip to content

Commit

Permalink
fix: don't add generic type when snippet has no params
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm committed Nov 23, 2023
1 parent 47f1928 commit 93418ff
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions packages/svelte2tsx/src/htmlxtojsx_v2/nodes/SnippetBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,27 @@ export function handleSnippet(
transforms.push([startEnd, snippetBlock.end]);
element.addProp([[snippetBlock.expression.start, snippetBlock.expression.end]], transforms);
} else {
// slap any on to it to silence "implicit any" errors; JSDoc people can't add types to snippets
let typeAnnotation = surroundWithIgnoreComments(`: import('svelte').Snippet<any>`);
if (snippetBlock.context?.typeAnnotation) {
typeAnnotation = surroundWithIgnoreComments(
`: import('svelte').Snippet<${str.original.slice(
snippetBlock.context.typeAnnotation.start,
snippetBlock.context.typeAnnotation.end
)}>`
);
}
const generic = snippetBlock.context
? snippetBlock.context.typeAnnotation
? `<${str.original.slice(
snippetBlock.context.typeAnnotation.start,
snippetBlock.context.typeAnnotation.end
)}>`
: // slap any on to it to silence "implicit any" errors; JSDoc people can't add types to snippets
'<any>'
: '';
const typeAnnotation = surroundWithIgnoreComments(`: import('svelte').Snippet${generic}`);
const transforms: TransformationArray = [
'var ',
[snippetBlock.expression.start, snippetBlock.expression.end],
typeAnnotation + ' = ('
];

if (snippetBlock.context) {
transforms.push([snippetBlock.context.start, snippetBlock.context.end]);
}
transforms.push(') => {');

transforms.push(') => {');
transform(str, snippetBlock.start, startEnd, startEnd, transforms);
}
}

0 comments on commit 93418ff

Please sign in to comment.