wretch icon indicating copy to clipboard operation
wretch copied to clipboard

`catcher()` / `catcherFallback()` return type drops addon extensions

Open biesbjerg opened this issue 1 month ago • 0 comments

Note: This issue was AI-generated, but the fix has been validated.

When chaining .addon() with .catcher() or .catcherFallback(), addon wretch-level methods are lost from the type.

Reproduction

import wretch from "wretch";
import AbortAddon from "wretch/addons/abort";

const base = wretch()
  .addon(AbortAddon())
  .catcher(404, (error) => { throw error; });

// ❌ TypeScript error: Property 'signal' does not exist
base.signal(new AbortController()).get("/test");

Cause

catcher() and catcherFallback() return Wretch<Self, ...> instead of Self & Wretch<Self, ...>, dropping the addon interface intersection.

Fix

File: src/types.ts (lines ~270 and ~289)

- catcher(...): Wretch<Self, Chain, Resolver, ErrorType extends undefined ? WretchError : ErrorType>;
+ catcher(...): Self & Wretch<Self, Chain, Resolver, ErrorType extends undefined ? WretchError : ErrorType>;

- catcherFallback(...): Wretch<Self, Chain, Resolver, ErrorType extends undefined ? WretchError : ErrorType>;
+ catcherFallback(...): Self & Wretch<Self, Chain, Resolver, ErrorType extends undefined ? WretchError : ErrorType>;

Note: customError() and resolve() already have the correct return type (Self & Wretch<...>).

Environment

  • wretch: 3.0.5

biesbjerg avatar Dec 05 '25 11:12 biesbjerg