Skip to content

Conversation

@DTCurrie
Copy link
Member

From the rule docs:

"any" (default) - If any variables in destructuring should be const, this rule warns for those variables.
"all" - If all variables in destructuring should be const, this rule warns the variables. Otherwise, ignores them.

The current behavior will complain if any field in a destructured object should be a const. This can be an issue in a case where you may want to use a destructured object where some fields are intended to change and others aren't. For example, in the case of using the $bindable rune in Svelte 5:

<script lang="ts">
interface Props {
  thing: string;
  element: HTMLDivElement | undefined
}

let { thing, element = $bindable() } = $props();
</script>

<div bind:this={element}></div>

In the above, a const cannot be use for a $bindable prop, so we must use let; however, the current rule would complain because thing should be treated a const.

@DTCurrie DTCurrie requested a review from mcous March 17, 2025 19:17
@DTCurrie DTCurrie self-assigned this Mar 17, 2025
Copy link
Contributor

@mcous mcous left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛝

@DTCurrie DTCurrie merged commit 6c61960 into main Mar 17, 2025
3 checks passed
@DTCurrie DTCurrie deleted the update-prefer-const branch March 17, 2025 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants