Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

vue/require-valid-default-prop false positive on arrays with props destructure assignment #2578

Copy link
Copy link
Closed
@aethr

Description

@aethr
Issue body actions

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: 8.50.0
  • eslint-plugin-vue version: 9.29.0
  • Vue version: 3.5.0
  • Node version:
  • Operating System:

Please show your full configuration:

module.exports = {
  parser: 'vue-eslint-parser',

  parserOptions: {
    parser: '@typescript-eslint/parser',
  },

  extends: ['plugin:vue/base'],

  rules: {
    'vue/require-valid-default-prop': 'error',
  },
};

What did you do?

<template>
  <div></div>
</template>

<script lang="ts" setup>
const {
  example = [],
} = defineProps<{
  example?: number[];
}>();
</script>

What did you expect to happen?

When assigning default values to props via props destructuring, arrays do not need to be generated by a function, and probably the same with objects. The vue documentation on props destructuring includes an example: https://vuejs.org/api/sfc-script-setup.html#reactive-props-destructure

I expected example = [] not to trigger the vue/require-valid-default-prop rule error.

What actually happened?

/home/projects/stackblitz-starters-reg1dy/test.vue
  8:19  error  Type of the default value for 'example' prop must be a function  vue/require-valid-default-prop

✖ 1 problem (1 error, 0 warnings)

Repository to reproduce this issue

https://stackblitz.com/edit/stackblitz-starters-qm6de7?file=test.vue

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.