HDB
HDB

Reputation: 812

VUEJS - Why do I get: Uncaught TypeError: Right-hand side of 'instanceof'?

I am facing issue in vue.js about "Uncaught TypeError: Right-hand side of 'instanceof' is not an object".

I am using Vue 2.2.1 version following is my code snippet where I am getting this issue.

Vue.component('componentName', {
'template': ``,
 props: {
  contentTypeUid: {
    type: 'string',
    required: false
  },
  limit: {
    type: 'number',
    required: false,
    default: 10
  }
 },
 ......
});

While if instead of above following working without any issue, but I want to use above format as I need to specify some validations and default values on props.

Vue.component('componentName', {
'template': ``,
 props: ["contentTypeUid", "limit"],
 ......
});

Thanks.

Upvotes: 20

Views: 33618

Answers (4)

Witold
Witold

Reputation: 893

My case:

    props: {
        userId: {
            type: String | Number,
        }
    },

changing to

  props: {
    userId: {
        type: [String, Number],
    }
},

helped

Upvotes: 0

nihils
nihils

Reputation: 311

In my case, it was a component property that had a null type:

props: {
    role:{
      type: [String, null],
      required: true
    },

changing it to

props: {
   role:{
      type: String,
      required: true
   },

And making sure, that the component always gets a string, fixed the issue. I guess the combination of required and a possible null value was not very good...

Upvotes: 4

Taggart Comet
Taggart Comet

Reputation: 128

Another case why this error might occur:

props: {
    prop_id: {
        required: true
    },
    title: 'Not specified'
},

So you need to change it to:

props: {
    prop_id: {
        required: true
    },
    title: {
        default: 'Not specified'
    }
},

Upvotes: 3

Юра Панарин
Юра Панарин

Reputation: 849

Use:

props: {
  contentTypeUid: {
    type: String, // not 'string'
    required: false
  },
  limit: {
    type: Number, // not 'number'
    required: false,
    default: 10
  }
 },

Upvotes: 33

Related Questions