T
TanStack14mo ago
correct-apricot

Change `useQuery` error type

Hi, I'm trying to update the error type for my useQuery calls to
export class HTTPError extends Error {
code: number;
url: string;
message: string;
constructor(res: Response) {
super(res.statusText);

this.code = res.status;
this.url = res.url;
this.message = res.statusText;
}
}
export class HTTPError extends Error {
code: number;
url: string;
message: string;
constructor(res: Response) {
super(res.statusText);

this.code = res.status;
this.url = res.url;
this.message = res.statusText;
}
}
So that I can access the status codes from the component. Unfortunately Typescript isn't letting me change the error type in the way I expected (see attached image). I get a "No overload matches this call" error. Any advice would be appreciated
No description
3 Replies
correct-apricot
correct-apricotOP14mo ago
specialQueryOptions being a fn that returns
queryOptions({
queryKey: ["special", x, y, type],
queryFn: () => GET(Endpoints.SPECIAL(x, y, type)),
});
queryOptions({
queryKey: ["special", x, y, type],
queryFn: () => GET(Endpoints.SPECIAL(x, y, type)),
});
sensitive-blue
sensitive-blue14mo ago
TypeScript | TanStack Query React Docs
React Query is now written in TypeScript to make sure the library and your projects are type-safe! Things to keep in mind:
correct-apricot
correct-apricotOP14mo ago
Thanks!

Did you find this page helpful?