mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
fix(types): restore AxiosError.cause type from unknown to Error (#7327)
* Initial plan * fix(types): restore AxiosError.cause type from unknown to Error Co-authored-by: jasonsaayman <4814473+jasonsaayman@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jasonsaayman <4814473+jasonsaayman@users.noreply.github.com>
This commit is contained in:
+1
-1
@@ -100,7 +100,7 @@ declare class AxiosError<T = unknown, D = any> extends Error {
|
|||||||
isAxiosError: boolean;
|
isAxiosError: boolean;
|
||||||
status?: number;
|
status?: number;
|
||||||
toJSON: () => object;
|
toJSON: () => object;
|
||||||
cause?: unknown;
|
cause?: Error;
|
||||||
event?: BrowserProgressEvent;
|
event?: BrowserProgressEvent;
|
||||||
static from<T = unknown, D = any>(
|
static from<T = unknown, D = any>(
|
||||||
error: Error | unknown,
|
error: Error | unknown,
|
||||||
|
|||||||
Vendored
+1
-1
@@ -431,7 +431,7 @@ export class AxiosError<T = unknown, D = any> extends Error {
|
|||||||
isAxiosError: boolean;
|
isAxiosError: boolean;
|
||||||
status?: number;
|
status?: number;
|
||||||
toJSON: () => object;
|
toJSON: () => object;
|
||||||
cause?: unknown;
|
cause?: Error;
|
||||||
event?: BrowserProgressEvent;
|
event?: BrowserProgressEvent;
|
||||||
static from<T = unknown, D = any>(
|
static from<T = unknown, D = any>(
|
||||||
error: Error | unknown,
|
error: Error | unknown,
|
||||||
|
|||||||
@@ -720,3 +720,12 @@ axios.get('/user', {
|
|||||||
return ['127.0.0.1', 4];
|
return ['127.0.0.1', 4];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// AxiosError.cause should be typed as Error to allow accessing .message
|
||||||
|
axios.get('/user').catch((error: AxiosError) => {
|
||||||
|
if (error.cause) {
|
||||||
|
// This should not produce a type error - cause is typed as Error
|
||||||
|
const causeMessage: string | undefined = error.cause.message;
|
||||||
|
console.log(causeMessage);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user