Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange multiple export typing issue #277

Closed
dkzlv opened this issue Jul 4, 2020 · 2 comments
Closed

Strange multiple export typing issue #277

dkzlv opened this issue Jul 4, 2020 · 2 comments
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release. good first issue Good for newcomers

Comments

@dkzlv
Copy link

dkzlv commented Jul 4, 2020

Describe the bug
It is by no means a severe bug, but a very strange one still.
If you define multiple props on the same line and divide them with a comma, all the props except the first one would raise an error, that they are not defined despite their type, but only in the template, not in the script.

To Reproduce
So JS/TS allows you to define as many lets, consts and exports in one line. I usually use this to save some keystrokes.
Here's the code that works fine and generates no errors:

<script lang="ts">
  export let callback: () => void;
</script>

<button on:click={callback}>Click</button>

but this one raises an error in the template:

<script lang="ts">
  export let name: string, callback: () => void;

  let wrappedCallback: () => void;
  // No error! Hover shows right type for `callback`
  $: wrappedCallback = () => callback();
</script>

<!-- Error: Variable 'callback' is used before being assigned. -->
<button on:click={callback}>{name}</button>

It is very strange, since semantically it's the same as

export let name: string;
export let callback: () => void;

Should also say that this code is treated well by the IDE:

<script lang="ts">
  const check1 = 'qwerty',
    check2 = 'qwerty';
</script>

<p>{check1}, {check2}</p>

Expected behavior
It shouldn't raise any errors.

System (please complete the following information):
OS: Mac OS 10.15.3
IDE: VS Code
Plugin/Package: Svelte for VS Code (the new official one)

@dkzlv dkzlv added the bug Something isn't working label Jul 4, 2020
@dummdidumm
Copy link
Member

Special case of #146, we need to adjust the regex to deal with this.

@dummdidumm
Copy link
Member

Probably the better solution would be to return some kind of info from svelte2tsx about the props. This would remove the need for the regex and be more robust since svelte2tsx uses the typescript parser to get these infos.

dummdidumm pushed a commit to dummdidumm/language-tools that referenced this issue Jul 28, 2020
`svelte2tsx` now also returns `exportedNames` through which we can easily get the props.
sveltejs#277
dummdidumm added a commit that referenced this issue Jul 29, 2020
* (fix) Swallow unused false positives

`svelte2tsx` now also returns `exportedNames` through which we can easily get the props.
#277
@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Jul 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release. good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants