0

I have a packet from npm that creates for me basic api with createApi() and in the same file it wraps this api with my custom function with that I can extend it with enhanceEndpoints, it's two different files and ts can't view types that I provided in my custom function, is it possible to make it in 2 files and to force to work ts with it?

for better undestanding I have main file like this:

export const api = createApi({
    reducerPath: 'api/test',
    baseQuery  : fetchBaseQuery({
        baseUrl: '/',
        //some options
    }),
    endpoints: (build) => ({
//some initial endpoints
    })
});


customFunctionProvided(api); 
export default api;

second file:

export const customFunctionProvided = (api: typeof apiType) => {
    api.enhanceEndpoints({
        //some logic
    }).injectEndpoints({ endpoints: (builder) => ({
        getSomething: builder.query({
            query: () => ({
                url: 'url',
            })
        }),
        
    }) });
};

so, I import first file in my project and ts can't find for example useGetSomethingQuery()...( is it has a way to work around?

Alan
  • 3
  • 1
  • 2
  • `customFunctionProvided` doesn't `return` anything, it just modifies the `api` variable. The `injectEndpoints` function actually has really strong types such that if you were to `return api.enhanceEndpoints(...).injectEndpoints(...)`, that returned object would have the right types. So then it would be fine to have `const enchancedApi = customFunctionProvided(api); export default enchancedApi ;`. But I'm unsure of what you can and can't change in your setup. What is the npm package that you are using? – Linda Paiste Aug 21 '22 at 23:10
  • As @LindaPaiste said, your function doesn't return an API, and simply extends it. I believe you just want to unwrap it, and have something like `export const extendedApi = api.enhanceEndpoints({...` – Sir Wrexes Dec 08 '22 at 20:47

0 Answers0