Sometimes, we want to set data type in Vue.js data object with TypeScript.
In this article, we’ll look at how to set data type in Vue.js data object with TypeScript.
How to set data type in Vue.js data object with TypeScript?
To set data type in Vue.js data object with TypeScript, we can set the type using as
.
For instance, we write
<template>
<div ref="root">This is a root element</div>
</template>
<script lang="ts">
export default {
//...
data() {
return {
players: [] as Player[],
};
},
//...
};
</script>
to set the players
reactive property to the Player[]
type with as Player[]
.
Conclusion
To set data type in Vue.js data object with TypeScript, we can set the type using as
.