Skip to content

<script setup> vue/no-mutating-props - Unexpected mutation of "isExpanded" prop #1702

Closed
@soerenmartius

Description

@soerenmartius

Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have read the FAQ and my problem is not listed.

Tell us about your environment

  • ESLint version: 7.32.0
  • eslint-plugin-vue version: 8.0.3
  • Node version: 14.17.2
  • Operating System: Darwin / MacOS

What did you do?

<script setup lang="ts">
import { defineEmits, defineProps, ref, watch, withDefaults } from 'vue'

import { FormEvents } from './types'

const emit = defineEmits<{
  (e: FormEvents.TOGGLED, isExpanded: boolean): void
}>()

interface Props {
  isExpanded?: boolean
}

const props = withDefaults(defineProps<Props>(), {
  isExpanded: false,
})

const isExpanded = ref(props.isExpanded)

watch(
  () => props.isExpanded,
  () => {
    isExpanded.value = props.isExpanded
  },
)

watch(isExpanded, () => emit(FormEvents.TOGGLED, isExpanded.value))
</script>

What did you expect to happen?

As isExpanded is redefined as a ref, eslint should pass. Instead it detects an error:

Screenshot 2021-11-10 at 14 28 07

What actually happened?

Eslint should pass since the prop doesn't get mutate directly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions