Skip to content

Commit

Permalink
Fix invoke type regression (#4110)
Browse files Browse the repository at this point in the history
  • Loading branch information
siddhsuresh authored Apr 3, 2023
1 parent f2da4f1 commit f84d77a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-boxes-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blitzjs/rpc": patch
---

Fix return type of the `invoke` method from returning type function to return the type of resolved data
12 changes: 6 additions & 6 deletions packages/blitz-rpc/src/client/invoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import {RpcClient} from "./rpc"
export async function invoke<T extends (...args: any) => any, TInput = FirstParam<T>>(
queryFn: T,
params: TInput,
): Promise<T>
): Promise<PromiseReturnType<T>>
export async function invoke<T extends (...args: any) => any, TInput = FirstParam<T>>(
queryFn: T,
params: TInput,
isServer: boolean,
): Promise<T>
): Promise<PromiseReturnType<T>>
export async function invoke<T extends (...args: any) => any, TInput = FirstParam<T>>(
queryFn: T,
params: TInput,
isServer = typeof window === "undefined" ? true : false,
): Promise<T> {
): Promise<PromiseReturnType<T>> {
if (typeof queryFn === "undefined") {
throw new Error(
"invoke is missing the first argument - it must be a query or mutation function",
Expand All @@ -28,15 +28,15 @@ export async function invoke<T extends (...args: any) => any, TInput = FirstPara
)
})
const ctx = await getBlitzContext()
return queryFn(params, ctx)
return queryFn(params, ctx) as PromiseReturnType<T>
}

if (isClient) {
const fn = queryFn as unknown as RpcClient
return fn(params, {fromInvoke: true}) as ReturnType<T>
return fn(params, {fromInvoke: true}) as PromiseReturnType<T>
} else {
const fn = queryFn as unknown as RpcClient
return fn(params) as ReturnType<T>
return fn(params) as PromiseReturnType<T>
}
}

Expand Down

0 comments on commit f84d77a

Please sign in to comment.