HomeContact
VueJS
How to set Type with Typescript in Vuejs Data.
March 04, 2021
1 min

To declare type in Data declaration in Vuejs, it’s simple. Let’s say you have a Typescript interface Player declared, and you want to use it in one of your Vuejs component. To use it for example in an Array of players, you will do :

data() {
  return {
    players: [] as Player[]
  };
},

You can also declare your Typescript type like this :

data() {
  return {
    players: new Array<Player>()
  };
},

Both will work and give the same results.

For more info on Typescript declaration, check the official documentation for Array type


Tags

javascriptvuejs

Related Posts

Add VueJS reactivity on nested object properties not declared in data
September 28, 2020
1 min
© 2023, All Rights Reserved.

Quick Links

Contact Us

Social Media