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
Unexpected Error when Destructing $store Values #444
Comments
Workaround
Of course you can always just refer to the store value directly in the DOM to see reactive updates. |
From input <script lang="ts">
import data from "./store";
$: ({ count } = $data);
</script>
<main>
<h1>Count (inline): {$data.count}</h1>
<h1>Count (reactive destructure): {count}</h1>
<button on:click={() => data.update(c => ({count: c.count + 1}))}>
Increment
</button>
</main>
<></>;
import data from "./store";
function render() {
;() => {$: ({ count } = __sveltets_store_get(data));}
;
() => (<>
<main>
<h1>Count (inline): {__sveltets_store_get(data).count}</h1>
<h1>Count (reactive destructure): {count}</h1>
<button onclick={() => data.update(c => ({count: c.count + 1}))}>
Increment
</button>
</main> </>);
return { props: {}, slots: {}, getters: {}, events: {} }}
export default class extends createSvelte2TsxComponent(__sveltets_partial(render)) {
} The problem is that the |
we might have to check how the svelte compiler determine when it should declare a variable see if we miss other situation |
The problem is the ts AST analysis. It only does the Edit: I'm in the middle of fixing this - all these if-then-also-think-of-this-corner-case-checks make my mind blurry 😄 |
I think the left check also needs to be changed
|
Yes, multiple things need to be changed. I'll create a draft PR so you can see my current state. |
* (fix) destructuring inside $ #444 * closer to a solution * remove ';' insertion * comment * support case where user defines some of the destructured variables * add ast extract identifiers util * support array destructuring * do all transformations in the end
Describe the bug
The statement
$: ({ value } = $store);
is valid syntax whenvalue
is a property of$store
and$store
is a Svelte store. It behaves like normal destructuring and is reactive to store updates. This produces an error whenlang="ts"
.To Reproduce
App.svelte
by addinglang="ts"
to the opening<script>
tag. (see the above snippet)svelte-check
Expected behavior
This is valid Svelte/JS syntax and his code runs fine. It should not produce typechecker errors.
Screenshots
If applicable, add screenshots to help explain your problem.
System (please complete the following information):
The text was updated successfully, but these errors were encountered: