-
-
Notifications
You must be signed in to change notification settings - Fork 221
Description
Describe the bug
When using Svelte Language Tools, TypeScript errors are encountered when destructuring an object in a reactive statement without explicitly declaring the variables first. This occurs even when TypeScript should be able to infer the types and assignments correctly. The expected behavior is that the destructuring should work without any TypeScript errors if the types can be inferred.
** This is a NEW bug, and this was working correctly up until recently. I am not sure of when this bug first appeared.
Reproduction
<script lang="ts">
const person: {
name: string;
age: number;
} = {
name: "John Doe",
age: 30,
};
$: ({ name, age } = person);
</script>In this example, I don't immediately see the same issue, but I do see that the type for age is inferred as an implicit any.
To contrast, note that declaring the variables before destructuring correctly types age as number:
<script lang="ts">
const person: {
name: string;
age: number;
} = {
name: "John Doe",
age: 30,
};
let name: string;
let age: number;
$: ({ name, age } = person);
</script>Expected behaviour
The types should be properly inferred when creating variables via a reactive statement without needing to declare them beforehand.
System Info
- OS: macOS Ventura v13.1 (22C65)
- IDE: VSCode v1.76.1 (Universal)
Which package is the issue about?
Svelte for VS Code extension
Additional Information, eg. Screenshots
Screen recording:
Screen.Recording.2023-03-14.at.3.41.10.PM.mov
It's also noteworthy that if I first initialize the variables this way, I can then destructure them the same way I did before and not get the same errors:
