Learn how to create interfaces using this method
types/index.ts
export interface AuthenticatedUser {
firstName: string,
lastName: string,
twitterHandle?: string,
location: Location
}
export interface Location {
city: string,
state: string
}
export interface Todo {
title: string;
}
import { AuthenticatedUser, Todo } from '@/types' // importing AuthenticatedUser interface
export default Vue.extend({
data: () => ({
authenticatedUser: {} as AuthenticatedUser //declaring authenticatedUser as type AuthenticatedUser
}),
name: 'Inputx' as string,
computed: {
fullName(): string { // Computed Property returns a string
return `${this.authenticatedUser.firstName} ${this.authenticatedUser.lastName}`
},
},
props: {
todos: {
type: Todo[], // declaring todos as array of Type Todo (Todo is the interface)
required: true,
default: []
}
},
mounted() {
this.authenticatedUser = {
firstName: `Dave`,
lastName: `Berning`,
twitterHandle: `@daveberning`,
location: {
city: `Cincinnati`,
state: `OH`
}
}
},
});
For further information on this topic, check out this resource and here