From d8233d9e8e9a64bfba9bbe01d475ba417510b82b Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Mon, 12 Jan 2026 16:20:00 +0200 Subject: [PATCH] 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> --- index.d.cts | 2 +- index.d.ts | 2 +- test/module/typings/esm/index.ts | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/index.d.cts b/index.d.cts index 4be32f9..80d22db 100644 --- a/index.d.cts +++ b/index.d.cts @@ -100,7 +100,7 @@ declare class AxiosError extends Error { isAxiosError: boolean; status?: number; toJSON: () => object; - cause?: unknown; + cause?: Error; event?: BrowserProgressEvent; static from( error: Error | unknown, diff --git a/index.d.ts b/index.d.ts index c562d9c..fa3110e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -431,7 +431,7 @@ export class AxiosError extends Error { isAxiosError: boolean; status?: number; toJSON: () => object; - cause?: unknown; + cause?: Error; event?: BrowserProgressEvent; static from( error: Error | unknown, diff --git a/test/module/typings/esm/index.ts b/test/module/typings/esm/index.ts index d0c8364..e44e3ec 100644 --- a/test/module/typings/esm/index.ts +++ b/test/module/typings/esm/index.ts @@ -720,3 +720,12 @@ axios.get('/user', { 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); + } +});