Skip to content

vue/no-setup-props-destructure should trigger when prop is passed to function #2092

Closed
@henribru

Description

@henribru

What rule do you want to change?
vue/no-setup-props-destructure
Does this change cause the rule to produce more or fewer warnings?
More.
How will the change be implemented? (New option, new default behavior, etc.)?
Perhaps an option that defaults to false would be best for backwards compatibility, though arguably it's more correct for it to be the default behavior.
Please provide some example code that this change will affect:

<script setup>
const props = defineProps(["foo"]);

function foo(bar) {};

foo(props.foo);
</script>

What does the rule currently do for this code?
Nothing.
What will the rule do after it's changed?
Flag it as a loss of reactivity. It should be foo(toRef(props, "foo")) or foo(computed(() => props.foo)) instead.
Additional context

The rule already flags code like const foo = props.foo. Passing it to a function incurs the same loss of reactivity, so it seems consistent to flag that as well. Note also that vue/no-ref-object-destructure already flags something like foo(bar.value) and that seems like an analogous case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions