JS.VUE.REQUIRE.PROP.TYPES

Require type definitions in props

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).

{'vue/require-prop-types': ['error']}

Copy
<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

  • Style guide - Prop definitions (https://vuejs.org/style-guide/rules-essential.html#use-detailed-prop-definitions)

The content on this page is adapted from the ESLint User Guide. Copyright © OpenJS Foundation and other contributors, www.openjsf.org. All rights reserved. https://eslint.org/docs/rules/