diff --git a/.changeset/nice-boxes-travel.md b/.changeset/nice-boxes-travel.md new file mode 100644 index 0000000000..511870c570 --- /dev/null +++ b/.changeset/nice-boxes-travel.md @@ -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 diff --git a/packages/blitz-rpc/src/client/invoke.ts b/packages/blitz-rpc/src/client/invoke.ts index 7b935cfa8b..fa44598e26 100644 --- a/packages/blitz-rpc/src/client/invoke.ts +++ b/packages/blitz-rpc/src/client/invoke.ts @@ -4,17 +4,17 @@ import {RpcClient} from "./rpc" export async function invoke any, TInput = FirstParam>( queryFn: T, params: TInput, -): Promise +): Promise> export async function invoke any, TInput = FirstParam>( queryFn: T, params: TInput, isServer: boolean, -): Promise +): Promise> export async function invoke any, TInput = FirstParam>( queryFn: T, params: TInput, isServer = typeof window === "undefined" ? true : false, -): Promise { +): Promise> { if (typeof queryFn === "undefined") { throw new Error( "invoke is missing the first argument - it must be a query or mutation function", @@ -28,15 +28,15 @@ export async function invoke any, TInput = FirstPara ) }) const ctx = await getBlitzContext() - return queryFn(params, ctx) + return queryFn(params, ctx) as PromiseReturnType } if (isClient) { const fn = queryFn as unknown as RpcClient - return fn(params, {fromInvoke: true}) as ReturnType + return fn(params, {fromInvoke: true}) as PromiseReturnType } else { const fn = queryFn as unknown as RpcClient - return fn(params) as ReturnType + return fn(params) as PromiseReturnType } }