Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: NuxtAxiosInstance no longer exported #555

Closed
silverbackdan opened this issue Dec 31, 2021 · 9 comments
Closed

Bug: NuxtAxiosInstance no longer exported #555

silverbackdan opened this issue Dec 31, 2021 · 9 comments

Comments

@silverbackdan
Copy link

Issue

The interface is no longer exported from type definitions and also results in an issue with the vuex.d.ts file:
https://github.com/nuxt-community/axios-module/blob/main/types/vuex.d.ts as this will try to import it as well.

Solution:

NuxtAxiosInstance should be exported here:
https://github.com/nuxt-community/axios-module/blob/main/types/index.d.ts

Related and possibly related:

@dubst3pp4
Copy link

Also affects our projects with nuxt 2.15.8 and @nuxtjs/axios 5.13.6.

@ThomasBerne
Copy link

I have the same problem

@cane-bt
Copy link

cane-bt commented Jan 25, 2022

I have the same problem in Same version as the quote below.

Also affects our projects with nuxt 2.15.8 and @nuxtjs/axios 5.13.6.

I got the following errors by vscode.

Module '"@nuxtjs/axios"' has no exported member '$axios'.

or

NuxtAxiosInstance not found in '@nuxtjs/axios'

Could anyone Help me?

@silverbackdan
Copy link
Author

Ping @pi0 (sorry I know you've been very helpful on issues in the past, thought I'd bring this to your attention in case it's a quick fix or you may ping someone who is best placed to take a look?)

@amirhoseinsalimi
Copy link

The solution is to use import type like so:

import type { NuxtAxiosInstance } from '@nuxtjs/axios';

@silverbackdan
Copy link
Author

silverbackdan commented Mar 9, 2022

Hi @amirhoseinsalimi

The NuxtAxiosInstance is not being exported to be able to import as a type.

Now it is here:
https://github.com/nuxt-community/axios-module/blob/main/types/index.d.ts#L6

It should be export interface NuxtAxiosInstance ... to work no?

@amirhoseinsalimi
Copy link

amirhoseinsalimi commented Mar 10, 2022

Hi @silverbackdan

I'm not 100% sure why the import type works but I think there's a so-called automatic type resolution mechanism that does this favor for us, so we can import non-exported types without any hassle. Also, I did some practices on my own, and find out that if a file is a type declaration file and uses import/export syntax (which turns it into a module), this automatic type resolution mechanism becomes enabled.

Remember that using a single import or export keyword, turns a file into a module.

Maybe a TypeScript expert can help more.

@silverbackdan
Copy link
Author

@amirhoseinsalimi How cool. Thanks for your time investigating and the solution. It's certainly resolved the issue for me so will close the issue and the detail you've given will stick with me for any type imports in future too. You rock.

@amirhoseinsalimi
Copy link

Thank YOU for asking this so I could think more about types :D. I'll update this thread once I get more information about this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants