Skip to content

Latest commit

 

History

History
71 lines (56 loc) · 1.55 KB

require-prop-types.md

File metadata and controls

71 lines (56 loc) · 1.55 KB
pageClass sidebarDepth title description
rule-details
0
vue/require-prop-types
require type definitions in props

vue/require-prop-types

require type definitions in props

  • ⚙️ This rule is included in "plugin:vue/strongly-recommended" and "plugin:vue/recommended".

📖 Rule Details

This rule enforces that a props statement contains type definition.

In committed code, prop definitions should always be as detailed as possible, specifying at least type(s).

<script>
/* ✓ GOOD */
Vue.component('foo', {
  props: {
    // Without options, just type reference
    foo: String,
    // With options with type field
    bar: {
      type: String,
      required: true,
    },
    // With options without type field but with validator field
    baz: {
      required: true,
      validator: function (value) {
        return (
          value === null ||
          Array.isArray(value) && value.length > 0
        )
      }
    }
  }
})

/* ✗ BAD */
Vue.component('bar', {
  props: ['foo']
})

Vue.component('baz', {
  props: {
    foo: {},
  }
})
</script>

🔧 Options

Nothing.

📚 Further reading

🔍 Implementation