DSteman
DSteman

Reputation: 1658

Typescript "Operator '+' cannot be applied to types '(() => any)"

I have a Vue component with Typescript and I keep receiving the error stated in the title of this issue, even though I declared types. The (simplified) component looks like this:

import Vue from 'vue';
const Component = Vue.extend({
  props: {
    value: {
      type: Number,
      default: null
    },
    index: {
      type: Number,
      required: true
    }
  },
  computed: {
    stepNumber(): number {
      return this.index + 1;
    }
  }
})

export default Component;

The issue is being raised for "this.index+1". To me this doesn't make sense, because I declared type 'number' for prop 'index'. Any thoughts?

Upvotes: 0

Views: 257

Answers (1)

Damian Kurek
Damian Kurek

Reputation: 180

Your index has no type number, it has object type with properties named type, and default. Also Number is JS built-in Number object, not type number.

More about types in TS: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html https://www.typescriptlang.org/docs/handbook/2/objects.html

Upvotes: 1

Related Questions