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

String content erased when inferring slot/event type from props #1113

Closed
geigerzaehler opened this issue Jul 23, 2021 · 5 comments
Closed

String content erased when inferring slot/event type from props #1113

geigerzaehler opened this issue Jul 23, 2021 · 5 comments
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.

Comments

@geigerzaehler
Copy link

geigerzaehler commented Jul 23, 2021

The following Svelte code fails to check with svelte-check v2.2.3.

<!-- Component.svelte -->
<script lang="typescript">
  export let variant: "foo" | "bar"
  export let style: string
</script>
<!-- index.svelte -->
<script lang="typescript">
  import Component from "./Component.svelte";
</script>

<Component
  variant="foo"
  style={`${
    1
  }`}
  on:click={() => {}}
/>

It shows the error

Error: Type '""' is not assignable to type '"foo" | "bar"'. (ts)
  on:click={() => {}}
/>

The example looks artificial but this layout is produced by prettier if the expression inside ${} is long.

@geigerzaehler geigerzaehler added the bug Something isn't working label Jul 23, 2021
@jasonlyu123
Copy link
Member

I can't reproduce the type-check error with the example you provide. The new Custom thing is supposed to be hidden from the type-check. The only thing I could think of it's that the component is generic and the props is used to infer a generic type parameter. It's that the problem you're encountering? If not can you provide another reproducible?

@geigerzaehler
Copy link
Author

You’re right. The code I posted works indeed. I assumed that I narrowed the error down to a minimal case. I’ll update the description with an example that indeed fails.

@jasonlyu123 jasonlyu123 changed the title String content erased when other attribute uses interpolation String content erased when inferring slot/event type from props Jul 28, 2021
@jasonlyu123
Copy link
Member

There're two problems with this one. The empty string is used to simplify transformation. In more cases, it shouldn't matter. The reason you're only encountering it with a template literal is that its multi-line. The multi-line causes the generated code to not been ignored properly with our current approach.

I fixed the empty string part (not released yet). But you might still encounter some problems with rename symbol when the identifier is referenced in the props. As the generated code is not being ignored. This one is more tricky to fix.

@jasonlyu123
Copy link
Member

The empty string part is released. You can try it again. I'll leave this open for the multi-line problem.

dummdidumm pushed a commit to dummdidumm/language-tools that referenced this issue Aug 24, 2021
@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Aug 24, 2021
@dummdidumm
Copy link
Member

The multiline problem is fixed now.

geigerzaehler added a commit to radicle-dev/radicle-upstream that referenced this issue Aug 30, 2021
Because of [a bug in svelte-check][1] we also replace single quotes with
a proper right single quote (’).

[1]: sveltejs/language-tools#1113

Signed-off-by: Thomas Scholtes <geigerzaehler@axiom.fm>
geigerzaehler added a commit to radicle-dev/radicle-upstream that referenced this issue Aug 31, 2021
Because of [a bug in svelte-check][1] we also replace single quotes with
a proper right single quote (’).

[1]: sveltejs/language-tools#1113

Signed-off-by: Thomas Scholtes <geigerzaehler@axiom.fm>
geigerzaehler added a commit to radicle-dev/radicle-upstream that referenced this issue Aug 31, 2021
Because of [a bug in svelte-check][1] we also replace single quotes with
a proper right single quote (’).

[1]: sveltejs/language-tools#1113

Signed-off-by: Thomas Scholtes <geigerzaehler@axiom.fm>
geigerzaehler added a commit to radicle-dev/radicle-upstream that referenced this issue Aug 31, 2021
Because of [a bug in svelte-check][1] we also replace single quotes with
a proper right single quote (’).

[1]: sveltejs/language-tools#1113

Signed-off-by: Thomas Scholtes <geigerzaehler@axiom.fm>
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.
Projects
None yet
Development

No branches or pull requests

3 participants