I am currently learning TypeScript and working on converting my project to TypeScript. However, I encountered an error while trying to use spread arguments. I have researched this topic, but I am still unsure of the correct usage.
Here is my current approach:
export const fetcher = async (...args) => {
return fetch(...args).then(async (res) => {
let payload;
try {
if (res.status === 204) return null; // 204 does not have body
payload = await res.json();
} catch (e) {
/* noop */
}
if (res.ok) {
return payload;
} else {
return Promise.reject(payload.error || new Error('Something went wrong'));
}
});
};
However, I am encountering an error on this line:
return fetch(...args).then(async (res) => {
A spread argument must either have a tuple type or be passed to a rest parameter