Reputation: 37018
I have the following two lines in a TypeScript file, trying to import some vanilla JS:
import axios from 'utils/UserSessionAPIAxios';
axios.doStuff(stringArgument);
This is my *.d.ts
file:
declare module 'utils/UserSessionAPIAxios' {
export const someData: string;
export type DoStuffFn = (data: string) => void;
export default interface UserSessionAPIAxios {
doStuff: DoStuffFn;
}
}
The corresponding JS file looks like this:
import axios from 'axios';
export const someData = 'data data data';
const userSessionAxios = axios;
userSessionAxios.doStuff = (data) => {
// omitted
};
export default userSessionAxios;
Why am I getting the error axios only refers to a type, but is being used as a value here
on the line where I'm calling doStuff
?
Upvotes: 0
Views: 2302
Reputation: 327634
I think you want to change your .d.ts
file to something like:
declare module 'utils/UserSessionAPIAxios' {
export const someData: string;
export type DoStuffFn = (data: string) => void;
export interface UserSessionAPIAxios {
doStuff: DoStuffFn;
}
export const userSessionAxios: UserSessionAPIAxios;
export default userSessionAxios;
}
The idea is that your default export is not the UserSessionAPIAxios
interface, it's a value whose type is that interface.
Hope that helps; good luck!
Upvotes: 3