language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

fix: support default parameter in snippet block

Open jasonlyu123 opened this issue 1 year ago • 4 comments

#2384

jasonlyu123 avatar Jun 03 '24 03:06 jasonlyu123

Still need to find a way to infer the type from the default value.

jasonlyu123 avatar Jun 03 '24 04:06 jasonlyu123

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.

dummdidumm avatar Jun 06 '24 12:06 dummdidumm

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.

jasonlyu123 avatar Jun 06 '24 13:06 jasonlyu123

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__]>

dummdidumm avatar Jun 07 '24 12:06 dummdidumm

Closing in favor of #2449

dummdidumm avatar Jul 30 '24 10:07 dummdidumm