imcvampire / vue-axios

A small wrapper for integrating axios to Vuejs
https://www.npmjs.com/package/vue-axios
MIT License
2.01k stars 182 forks source link

'AxiosInstance' is not assignable to parameter of type 'AxiosStatic' #173

Open 1e4 opened 4 months ago

1e4 commented 4 months ago

I have http.js configuring axios however when importing it it fails with

src/main.ts(16,19): error TS2769: No overload matches this call.
-- | --
Overload 1 of 2, '(plugin: Plugin<[axios: AxiosStatic]>, axios: AxiosStatic): App<Element>', gave the following error.
Argument of type 'AxiosInstance' is not assignable to parameter of type 'AxiosStatic'.
Type 'AxiosInstance' is missing the following properties from type 'AxiosStatic': create, Cancel, CancelToken, Axios, and 12 more.
Overload 2 of 2, '(plugin: Plugin<[axios: AxiosStatic]>, options: [axios: AxiosStatic]): App<Element>', gave the following error.
Argument of type 'AxiosInstance' is not assignable to parameter of type '[axios: AxiosStatic]'.
src/main.ts(16,19): error TS2769: No overload matches this call.
Overload 1 of 2, '(plugin: Plugin<[axios: AxiosStatic]>, axios: AxiosStatic): App<Element>', gave the following error.
Argument of type 'AxiosInstance' is not assignable to parameter of type 'AxiosStatic'.
Type 'AxiosInstance' is missing the following properties from type 'AxiosStatic': create, Cancel, CancelToken, Axios, and 12 more.
Overload 2 of 2, '(plugin: Plugin<[axios: AxiosStatic]>, options: [axios: AxiosStatic]): App<Element>', gave the following error.
Argument of type 'AxiosInstance' is not assignable to parameter of type '[axios: AxiosStatic]'.
ERROR: "type-check" exited with 2.

http.js

import axios from 'axios'

const http = axios.create({
  baseURL: import.meta.env.VITE_API_URL
});

export default http;

main.js

import './assets/main.css'

import { createApp } from 'vue'
import { createPinia } from 'pinia'

import App from './App.vue'
import router from './router'

import http from './http'
import VueAxios from 'vue-axios'

const app = createApp(App)

app.use(createPinia())
app.use(router)
app.use(VueAxios, http)

app.mount('#app')

This works fine with javascript and only fails with TypeScript. I'm sure it's something simple to fix. I checked the tickets and saw there may be issues with types and such as there doesn't seem to be full TS support.

Does anyone have a solution for this?