diff --git a/src/resolver.ts b/src/resolver.ts index 77f1928..f60aedd 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -95,7 +95,7 @@ export const resolver = (wretch: T & Wretch) => { }) } // Enforces the proper promise type when a body parsing method is called. - type BodyParser = (funName: string | null) => (cb?: (type: Type) => Result) => Promise> + type BodyParser = (funName: "json" | "blob" | "formData" | "arrayBuffer" | "text" | null) => (cb?: (type: Type) => Result) => Promise> const bodyParser: BodyParser = funName => cb => funName ? // If a callback is provided, then callback with the body result otherwise return the parsed body itself. catchersWrapper(throwingPromise.then(_ => _ && _[funName]()).then(_ => cb ? cb(_) : _)) : @@ -127,7 +127,7 @@ export const resolver = (wretch: T & Wretch) => { const enhancedResponseChain: R extends undefined ? Chain & WretchResponseChain : R = addons.reduce((chain, addon) => ({ ...chain, - ...(addon.resolver as any) + ...(typeof addon.resolver === "function" ? (addon.resolver as (_: WretchResponseChain) => any)(chain) : addon.resolver) }), responseChain) return resolvers.reduce((chain, r) => r(chain, wretch), enhancedResponseChain) diff --git a/src/types.ts b/src/types.ts index 61061b9..e69d2de 100644 --- a/src/types.ts +++ b/src/types.ts @@ -786,6 +786,6 @@ export type FetchLike = (url: string, opts: WretchOptions) => Promise = { beforeRequest?(wretch: T & Wretch, options: WretchOptions, state: Record): T & Wretch, wretch?: W, - resolver?: R + resolver?: R | ((_: C & WretchResponseChain) => R) } diff --git a/tsconfig.json b/tsconfig.json index ebc134c..8942c9c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,7 +17,6 @@ "isolatedModules": true }, "include": [ - "src/**/*", - "test.ts" + "src/**/*" ] } \ No newline at end of file