Skip to content

Commit

Permalink
feat: add types dir
Browse files Browse the repository at this point in the history
  • Loading branch information
kieranwv committed Nov 21, 2024
1 parent 289f661 commit 1d0d45f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
12 changes: 4 additions & 8 deletions app/pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script lang="ts" setup>
import type { TodoList } from '~~/shared/types/todo'
definePageMeta({
name: 'Index',
layout: 'page',
Expand All @@ -11,13 +13,7 @@ const { headerLogo } = storeToRefs(useLayoutStore())
const { toggleLogo } = useLayoutStore()
interface TodoItem {
id: number
title: string
completed: boolean
}
const todoList = ref<TodoItem[]>([])
const todoList = ref<TodoList>([])
const emptyText = ref('')
Expand All @@ -28,7 +24,7 @@ async function fetchData() {
return
loading.value = true
try {
const res = await $fetch<TodoItem[]>('/api/todos')
const res = await $fetch<TodoList>('/api/todos')
todoList.value = res
}
catch (e) {
Expand Down
1 change: 0 additions & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export default defineNuxtConfig({
// https://nuxt.com/docs/api/nuxt-config#imports
imports: {
dirs: [
'apis',
'constants',
'stores',
],
Expand Down
28 changes: 28 additions & 0 deletions shared/types/todo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Todo item type.
*/
export interface TodoItem {
/**
* Todo item id.
*/
id: number
/**
* Todo item title.
*/
title: string
/**
* Todo item completed.
*
* @default false
*/
completed: boolean
/**
* Todo item user id.
*/
userId: number
}

/**
* Todo list type.
*/
export type TodoList = TodoItem[]

0 comments on commit 1d0d45f

Please sign in to comment.