Skip to content

Commit

Permalink
🐛 Fix type inconsistencies in the body parsers
Browse files Browse the repository at this point in the history
Should fix #143
  • Loading branch information
elbywan committed Sep 27, 2022
1 parent 5520b06 commit b7cae7e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const resolver = <T, Chain, R>(wretch: Wretch<T, Chain, R>) => {
})
}
// Enforces the proper promise type when a body parsing method is called.
type BodyParser = <Type>(funName: string | null) => <Result = void>(cb?: (type: Type) => Result) => Promise<Result>
type BodyParser = <Type>(funName: string | null) => <Result = void>(cb?: (type: Type) => Result) => Promise<Awaited<Result>>
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(_) : _)) :
Expand Down
12 changes: 6 additions & 6 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ export interface WretchResponseChain<T, Self = unknown, R = undefined> {
*
* @category Response Type
*/
res: <Result = WretchResponse>(cb?: (type: WretchResponse) => Result) => Promise<Result>,
res: <Result = WretchResponse>(cb?: (type: WretchResponse) => Promise<Result> | Result) => Promise<Awaited<Result>>,
/**
* Read the payload and deserialize it as JSON.
*
Expand All @@ -572,7 +572,7 @@ export interface WretchResponseChain<T, Self = unknown, R = undefined> {
*
* @category Response Type
*/
json: <Result = unknown>(cb?: (type: Result) => Result) => Promise<Result>,
json: <Result = unknown>(cb?: (type: any) => Promise<Result> | Result) => Promise<Awaited<Result>>,
/**
* Read the payload and deserialize it as a Blob.
*
Expand All @@ -582,7 +582,7 @@ export interface WretchResponseChain<T, Self = unknown, R = undefined> {
*
* @category Response Type
*/
blob: <Result = Blob>(cb?: (type: Blob) => Result) => Promise<Result>,
blob: <Result = Blob>(cb?: (type: Blob) => Promise<Result> | Result) => Promise<Awaited<Result>>,
/**
* Read the payload and deserialize it as a FormData object.
*
Expand All @@ -592,7 +592,7 @@ export interface WretchResponseChain<T, Self = unknown, R = undefined> {
*
* @category Response Type
*/
formData: <Result = FormData>(cb?: (type: FormData) => Result) => Promise<Result>,
formData: <Result = FormData>(cb?: (type: FormData) => Promise<Result> | Result) => Promise<Awaited<Result>>,
/**
* Read the payload and deserialize it as an ArrayBuffer object.
*
Expand All @@ -602,7 +602,7 @@ export interface WretchResponseChain<T, Self = unknown, R = undefined> {
*
* @category Response Type
*/
arrayBuffer: <Result = ArrayBuffer>(cb?: (type: ArrayBuffer) => Result) => Promise<Result>,
arrayBuffer: <Result = ArrayBuffer>(cb?: (type: ArrayBuffer) => Promise<Result> | Result) => Promise<Awaited<Result>>,
/**
* Retrieves the payload as a string.
*
Expand All @@ -612,7 +612,7 @@ export interface WretchResponseChain<T, Self = unknown, R = undefined> {
*
* @category Response Type
*/
text: <Result = string>(cb?: (type: string) => Result) => Promise<Result>,
text: <Result = string>(cb?: (type: string) => Promise<Result> | Result) => Promise<Awaited<Result>>,

/**
* Catches an http response with a specific error code or name and performs a callback.
Expand Down

0 comments on commit b7cae7e

Please sign in to comment.