sveltejs/language-tools

Wrong types are genereted for snippets with optional arguments

Closed this issue · 1 comments

7nik commented

Describe the bug

Optional arguments became required, and arguments with fallbacks, except the first one, are thrown away from the typing.

Reproduction

{#snippet snip1(a = "", b = "", c = "")}
  {a}{b}{c}
{/snippet}
<!-- (local var) snip1: (this: void, args_0: any) => typeof SnippetReturn & {_: "...";} -->
{@render snip1("", "", "")} <!-- Error: Expected 1 arguments, but got 3. -->

{#snippet snip2(a?: string, b?: string, c?: string)}
  {a}{b}{c}
{/snippet}
<!-- (local var) snip2: (this: void, args_0: string, args_1: string, args_2: string) => typeof SnippetReturn & {_: "...";} -->
{@render snip2()} <!-- Error: Expected 3 arguments, but got 0. -->

Expected behaviour

No typing errors.

System Info

  • Version: 1.89.1
  • Commit: dc96b837cf6bb4af9cd736aa3af08cf8279f7685
  • Date: 2024-05-16T09:26:03.059Z
  • Electron: 28.3.3
  • ElectronBuildId: undefined
  • Chromium: 120.0.6099.291
  • Node.js: 18.18.2
  • V8: 12.0.267.19-electron.0
  • OS: Linux x64 6.6.32-1-MANJARO
  • Svelte for VSCode: v108.5.0
  • svelte-check: 3.8.4

Which package is the issue about?

Svelte for VS Code extension

Additional Information, eg. Screenshots

No response

7nik commented

The first case seems to be caused by sveltejs/svelte#12067