Replies: 2 comments
-
what do you mean about "React Server Components" here? i also don't see createServerFn() being used in your example. can you please provide a complete example repo? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Please see Argument of type '() => Promise<SayResponse>' is not assignable to parameter of type 'ServerFn<Method, "data", undefined, undefined, SayResponse>'.
Type 'Promise<SayResponse>' is not assignable to type 'Promise<{ readonly $typeName: "connectrpc.eliza.v1.SayResponse"; $unknown?: { readonly no: number; readonly wireType: WireType; readonly data: { [x: number]: number; readonly BYTES_PER_ELEMENT: number; ... 32 more ...; readonly [Symbol.toStringTag]: "Uint8Array"; }; }[] | undefined; sentence: string; }> | { ...; }'.
Type 'Promise<SayResponse>' is not assignable to type 'Promise<{ readonly $typeName: "connectrpc.eliza.v1.SayResponse"; $unknown?: { readonly no: number; readonly wireType: WireType; readonly data: { [x: number]: number; readonly BYTES_PER_ELEMENT: number; ... 32 more ...; readonly [Symbol.toStringTag]: "Uint8Array"; }; }[] | undefined; sentence: string; }>'.
Type 'SayResponse' is not assignable to type '{ readonly $typeName: "connectrpc.eliza.v1.SayResponse"; $unknown?: { readonly no: number; readonly wireType: WireType; readonly data: { [x: number]: number; readonly BYTES_PER_ELEMENT: number; ... 32 more ...; readonly [Symbol.toStringTag]: "Uint8Array"; }; }[] | undefined; sentence: 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]: string; } | { ...; }; ... 31 more ...; readonly [Symbol.toStringTag]: "Ui...'.
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]: string; } | { ...; }; ... 31 more ...; readonly [Symbol.toStringTag]: "Ui...'.
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]: string; } | { ...; }; ... 31 more ...; readonly [Symbol.toStringTag]: "Ui...'.
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]: string; } | { readonly byteLength: number; slice: "Function is not serializable"; readonly [Symbol.species]: ...; readonly [Symbol.toStringTag]: "SharedArrayBuffer"; }'.
Type 'ArrayBuffer' is not assignable to type '{ readonly byteLength: number; slice: "Function is not serializable"; readonly [Symbol.toStringTag]: string; } | { readonly byteLength: number; slice: "Function is not serializable"; readonly [Symbol.species]: ...; readonly [Symbol.toStringTag]: "SharedArrayBuffer"; }'.
Type 'ArrayBuffer' is not assignable to type '{ readonly byteLength: number; slice: "Function is not serializable"; readonly [Symbol.toStringTag]: string; }'.
Types of property 'slice' are incompatible.
Type '(begin: number, end?: number | undefined) => ArrayBuffer' is not assignable to type '"Function is not serializable"'.ts(2345) ![]() |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Description
When using TanStack Start’s React example together with a Buf Connect client (from the official Connect-ES examples), a
ServerFn
handler that simply returns the Protobuf message instance is rejected by TypeScript’s typing because it includes internal fields like$unknown
and binary data (Uint8Array
/ArrayBuffer
). In practice these message objects are fully structured-cloneable, but the currentServerFn
generic is too strict and treats them as non-serializable.Reproduction
Clone and set up the official examples:
git clone https://github.com/TanStack/router.git cd router/examples/react npm install
Install Buf Connect packages:
In
src/server.ts
add a simple RPC route that returns the raw message from Connect:Observe the error:
Versions
Expected Behavior
ServerFn handlers should be allowed to return any structured-cloneable value, including Buf-Connect message instances containing binary fields (Uint8Array, ArrayBuffer) or optional
$unknown
arrays. Under the hood, React Server Components (and TanStack Server Functions) use structured cloning, which supports these types.Suggested Fixes
Loosen the
ServerFn
return-type constraint to accept any object that passes structured-cloning rules (not just pure JSON).Provide a way to explicitly mark a return type as “bypass strict JSON check”, so advanced use-cases (e.g. Protobuf) work out of the box.
(Optional) Add built-in support for Buf-Connect messages by recognizing
MessageShape<T>
and treating them as serializable.Beta Was this translation helpful? Give feedback.
All reactions