Skip to content

Cannot use connectRPC call inside tanstack start server function #6141

@Quadrubo

Description

@Quadrubo

Which project does this relate to?

Router

Describe the bug

I'm having some typing issues with using connectrpc in tanstack start.
I have the following server function.

export const login = createServerFn()
  .validator((data: unknown) => {
    return data as LoginRequest
  })
  .handler(async ({ data }) => {
    const authClient = await createGRPCClient(AuthService)
    return await authClient.login({
      email: data.email,
      password: data.password,
    })
  })

This results in this typing error.

TS2345: Argument of type

({data}: ServerFnCtx<Method, "data", undefined, (data: unknown) => LoginRequest>) => Promise<LoginResponse>

is not assignable to parameter of type

ServerFn<Method, "data", undefined, (data: unknown) => LoginRequest, LoginResponse>

Type 'Promise<LoginResponse>' is not assignable to type 'Promise<{ readonly $typeName: "api.auth.v1.LoginResponse"; $unknown?: { readonly no: number; readonly wireType: WireType; readonly data: { [x: number]: number; readonly BYTES_PER_ELEMENT: number; ... 32 more ...; readonly [Symbol.toStringTag]: "Uint8Array"; }; }[] | undefined; jwt: string; }> | { ...; }'.

Type 'Promise<LoginResponse>' is not assignable to type 'Promise<{ readonly $typeName: "api.auth.v1.LoginResponse"; $unknown?: { readonly no: number; readonly wireType: WireType; readonly data: { [x: number]: number; readonly BYTES_PER_ELEMENT: number; ... 32 more ...; readonly [Symbol.toStringTag]: "Uint8Array"; }; }[] | undefined; jwt: string; }>'.

Type 'LoginResponse' is not assignable to type '{ readonly $typeName: "api.auth.v1.LoginResponse"; $unknown?: { readonly no: number; readonly wireType: WireType; readonly data: { [x: number]: number; readonly BYTES_PER_ELEMENT: number; ... 32 more ...; readonly [Symbol.toStringTag]: "Uint8Array"; }; }[] | undefined; jwt: string; }'.

Types of property $unknown are incompatible.

Type 'UnknownField[] | undefined' is not assignable to type '{ readonly no: number; readonly wireType: WireType; readonly data: { [x: number]: number; readonly BYTES_PER_ELEMENT: number; readonly buffer: { readonly byteLength: number; slice: "Function is not serializable"; readonly [Symbol.toStringTag]: "ArrayBuffer"; } | { ...; }; ... 31 more ...; readonly [Symbol.toStringTa...'.

Type 'UnknownField[]' is not assignable to type '{ readonly no: number; readonly wireType: WireType; readonly data: { [x: number]: number; readonly BYTES_PER_ELEMENT: number; readonly buffer: { readonly byteLength: number; slice: "Function is not serializable"; readonly [Symbol.toStringTag]: "ArrayBuffer"; } | { ...; }; ... 31 more ...; readonly [Symbol.toStringTa...'.

Type 'UnknownField' is not assignable to type '{ readonly no: number; readonly wireType: WireType; readonly data: { [x: number]: number; readonly BYTES_PER_ELEMENT: number; readonly buffer: { readonly byteLength: number; slice: "Function is not serializable"; readonly [Symbol.toStringTag]: "ArrayBuffer"; } | { ...; }; ... 31 more ...; readonly [Symbol.toStringTa...'.

The types of data.buffer are incompatible between these types.

Type ArrayBufferLike is not assignable to type

{

    readonly byteLength: number;

    slice: "Function is not serializable";

    readonly [Symbol.toStringTag]: "ArrayBuffer";

} | {

    readonly byteLength: number;

    slice: "Function is not serializable";

    readonly [Symbol.toStringTag]: "SharedArrayBuffer";

}

Type ArrayBuffer is not assignable to type

{

    readonly byteLength: number;

    slice: "Function is not serializable";

    readonly [Symbol.toStringTag]: "ArrayBuffer";

} | {

    readonly byteLength: number;

    slice: "Function is not serializable";

    readonly [Symbol.toStringTag]: "SharedArrayBuffer";

}

Type ArrayBuffer is not assignable to type

{

    readonly byteLength: number;

    slice: "Function is not serializable";

    readonly [Symbol.toStringTag]: "ArrayBuffer";

}

Types of property slice are incompatible.

Type

(begin?: number | undefined, end?: number | undefined) => ArrayBuffer

is not assignable to type "Function is not serializable"

I have also tried using the create function but this produces the same error.

Also see the issue here: bufbuild/protobuf-es#1232
Using json_types is not a proper solution as important type information gets lost

Your Example Website or App

https://github.com/Quadrubo/protoc-arraybuffer-repro

Steps to Reproduce the Bug or Issue

Follow the steops in this repro repo: https://github.com/Quadrubo/protoc-arraybuffer-repro

Expected behavior

I expect to receive no type errors and be able to use server functions like normal.

Screenshots or Videos

No response

Platform

  • Router / Start Version: 1.141.7
  • Bundler: vite
  • Bundler Version: 7.3.0

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions