T
TanStack3y ago
deep-jade

auto get Error ?

i have this code useQuery automatically getting type whatever m passing in axios type but i want to add Error type on all axios call that should get in use Query like so <IFetchResponse<Game>, Error> but instead of typing manually it should take automatically
No description
9 Replies
deep-jade
deep-jadeOP3y ago
@bostonsheraff kindly guide thanks is it possible
deep-jade
deep-jadeOP3y ago
like here m passing manually - i dont want to pass it should get whatever api return data type na
No description
deep-jade
deep-jadeOP3y ago
m not able to get Error type if i dont type manually in useQUery
No description
deep-jade
deep-jadeOP3y ago
@bostonsheraff data result m getting fine
environmental-rose
environmental-rose3y ago
Sadly Typescript does not type the errors so I don't think you can do this automatically. The languages that type their errors have some form of "wrapping / unwrapping" system, like Rust's
enum Result<T, E> {
Ok(T),
Err(E),
}
enum Result<T, E> {
Ok(T),
Err(E),
}
In javascript / typescript, virtually any function can throw any type or variable and the information is not known anywhere
deep-jade
deep-jadeOP3y ago
so is there any workaround ? i tried like this not working
No description
deep-jade
deep-jadeOP3y ago
No description
deep-jade
deep-jadeOP3y ago
@bostonsheraff
environmental-rose
environmental-rose3y ago
No workaround that I know of. Just useQuery<TData, E> everywhere instead of useQuery<TData>, which is really just 3 characters more

Did you find this page helpful?