VueJs Axios and Typescript VueJs Axios and Typescript typescript typescript

VueJs Axios and Typescript


I'm encapsulate HTTP/REST operations in separate .ts files and which I then call form a component or from the Vuex store. Here I also use async/await to have better readable code. Each method declared its input and return types.

import axios from 'axios'const http = axios.create({  baseURL: `${SOME_SERVICE_URL}/base-path`,  headers: { 'Content-Type': 'application/json' }})export async function getItemById (itemId: string): Promise<Item> {  const response = await http.get(`/${itemId}`)  return response.data}export async function createItem (item: Item): Promise<Item> {  const response = await http.post('/', JSON.stringify(item))  return response.data}