RoToRa
RoToRa

Reputation: 38441

What is the type for a Vue prop when declared in an array?

I have an existing Vue component with multiple props which are declared in an array without types:

props: ["prop1", "prop2"]

I'd now like to add a new prop with the type Boolean. This requires me to change the array to an object and set the type for the existing properties.

props: {
   "prop1": ???,
   "prop2": ???,
   "newProp": Boolean
}

What type do I need to choose in place of ??? so that nothing is changed in regards to those props? I assume Object, but I can't find any documentation to confirm that.

Upvotes: 0

Views: 1111

Answers (1)

Owl
Owl

Reputation: 6853

It depends on what prop1 and prop2 will be, based on the docs you can pass null or undefined to make it any type.

props: {
   "prop1": null,
   "prop2": null,
   "newProp": Boolean
}

Or if you already know what type of prop1 and prop2 will be, you can pass a type instead.

The type can be one of the following native constructors:

  • String
  • Number
  • Boolean
  • Array
  • Object
  • Date
  • Function
  • Symbol

From: https://v2.vuejs.org/v2/guide/components-props.html#Type-Checks

Upvotes: 2

Related Questions