language-tools
language-tools copied to clipboard
fix: support default parameter in snippet block
#2384
Still need to find a way to infer the type from the default value.
What do you mean by "infer the type from the default value"? Also, this feels like something we could fix in the Svelte parser instead - feels wrong that start/end isn't set for it.
What do you mean by "infer the type from the default value"?
Because of the type annotation, the type for the parameter would be any instead of inferring from the default value like functions usually do.
This feels like something we could fix in the Svelte parser instead.
Sure. We can deal with this type of problem later. I can't really think of a way to let ts infer the type now.
I pushed a fix to Svelte to make the default parameter appear correctly. What's left is the default type inference problem.
We could do something like: check if the default parameter references a variable outside the snippet code
- if yes, then do this generation":
: Snippet<[typeof defaultValue] - if not, assign default value to a bogus variable and then do typeof:
const __asd__ = 'default value literal'.... : Snippet<[typeof __asd__]>
Closing in favor of #2449