Skip to content

Latest commit

 

History

History
55 lines (43 loc) · 1.5 KB

optional-props-using-with-defaults.md

File metadata and controls

55 lines (43 loc) · 1.5 KB
pageClass sidebarDepth title description
rule-details
0
vue/optional-props-using-with-defaults
enforce props with default values ​​to be optional

vue/optional-props-using-with-defaults

enforce props with default values ​​to be optional

  • 🔧 The --fix option on the command line can automatically fix some of the problems reported by this rule.

📖 Rule Details

This rule enforce props with default values ​​to be optional. Because when a required prop declared with a default value, but it doesn't be passed value when using it, it will be assigned the default value. So a required prop with default value is same as a optional prop.

<script setup lang="ts">
  /* ✓ GOOD */
  const props = withDefaults(
    defineProps<{
      name?: string | number
      age?: number
    }>(),
    {
      name: "Foo",
    }
  );

  /* ✗ BAD */
  const props = withDefaults(
    defineProps<{
      name: string | number
      age?: number
    }>(),
    {
      name: "Foo",
    }
  );
</script>

🔧 Options

Nothing.

🔍 Implementation