I am trying to limit the Record type of params passed to URLSearchParams to a specific amount of strings as shown below:
interface GetCoordsParams {
params: Record<'city' | 'appid' | 'limit', string>;
};
export const createGetCoordsQuery = async (params: GetCoordsParams) => {
const query = new URLSearchParams(params).toString();
await fetch(`http://api.geo.com/1.0/direct?q=${query}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
},
});
};
Unfortunately, typescript doesn't let me do that by throwing
Argument of type 'GetCoordsParams' is not assignable to parameter of type 'string | string[][] | Record<string, string> | URLSearchParams | undefined'.