'How to infer type from query in RTK Query?

How to infer the type of the data coming from the query so that, I can have autocompletion in VS Code when populating my UI? I have been having a look at the content in the official docs but I was not able to understand how to do it,

https://redux-toolkit.js.org/rtk-query/api/fetchBaseQuery

Code below:

import {createApi, fetchBaseQuery} from '@reduxjs/toolkit/query/react'

interface WeatherQuery {
    lat: Number | null;
    lon: Number | null;
    appid: string
}

export const coordQueryApi = createApi({
    reducerPath: 'coordQueryApi',
    baseQuery: fetchBaseQuery({ baseUrl: 'https://api.openweathermap.org/data/2.5/'}),
    endpoints: (builder) => ({
        getCurrentPositionWeather: builder.query<any,WeatherQuery>({
            query: (arg) =>{
                const {lat, lon, appid} = arg
                return {
                    url: '/weather',
                    params: {lat, lon, appid}
                }
            }
        })
    })
})

export const { useGetCurrentPositionWeatherQuery } = coordQueryApi

thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source