Return value of function-typed Vue options should be a valid type

  • VUE_BAD_API_RETURN_VALUE
  • Error
  • Medium
  • vue

This rule applies when the return value of a function-typed Vue option is invalid.

If an invalid value is returned from a function-typed Vue option, it may cause a problem when Vue uses the value. Even when no immediate problem occurs, the value becomes meaningless.

The options which cause problem for an invalid return value are listed below with the valid return values:

  1. setup(): Object, Function, or undefined
  2. data(): Object
  3. errorCaptured() lifecycle hook: false, undefined, or null

Also, this rule checks the following lifecycle hooks which need no return value:

  1. beforeCreate()
  2. created()
  3. beforeMount()
  4. mounted()
  5. beforeUpdate()
  6. updated()
  7. beforeUnmount()
  8. unmounted()
  9. renderTracked()
  10. renderTriggered()
  11. activated()
  12. deactivated()

In the above cases, returning a value has no effect.

Noncompliant Code Example

View with compliant examples side by side
<script>
export default {
  data() {
    return 'data'; // VUE_BAD_API_RETURN_VALUE alarm because 'data()' does not return an object.
  },
  beforeCreate() {
    return true; // VUE_BAD_API_RETURN_VALUE alarm because 'beforeCreate()' does not need a return value.
  }
}
</script>

Compliant Code Example

View with noncompliant examples side by side
<script>
export default {
  data() {
    return { msg: 'hi' };
  },
  beforeCreate() {
    // do something
  }
}
</script>

Version

This rule was introduced in DeepScan 1.14.0-beta.

See

Was this documentation helpful?