0๐
โ
I found an answer to my problem. The method is not a member of the class, since it is never bound to this.
I fixed this in the most typescripty way I could find, using arrow functions. Simply binding in the constructor gave me another error, which I then found out I had to correct certain places in the Api class as well.
The resulting portalService.ts
looks like this:
import { Portal } from '@/interfaces/portal';
import { AxiosRequestConfig, AxiosResponse } from 'axios';
import { apiConfig } from './config/api.config';
import { Api } from './superclasses/api';
const api = '/portals';
export class PortalService extends Api {
constructor(config: AxiosRequestConfig) {
super(config);
}
public getPortals = async (): Promise<Portal[]> => {
const portals = await this.get<Portal, AxiosResponse<Portal[]>>(api);
return this.success(portals);
};
}
export const portalService = new PortalService(apiConfig);
Source:stackexchange.com