You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How can I avoid this error when I use Branded Types?
Here is a minimal reproduce-able code :
import{z}from"zod";constFooSchema=z.object({id: z.string().brand("FooId"),});typeFoo=z.infer<typeofFooSchema>;constgetFoo=createServerFn({method: "GET",}).handler(()=>{// here I get a type error.returnFooSchema.parse({id: "foo"});});
And the error is: Argument of type '() => { id: string & z.BRAND<"FooId">; }' is not assignable to parameter of type 'ServerFn<"GET", undefined, undefined, { id: string & BRAND<"FooId">; }>'. Type '{ id: string & BRAND<"FooId">; }' is not assignable to type '{ id: { readonly [x: number]: string; toString: "Function is not serializable"; charAt: "Function is not serializable"; charCodeAt: "Function is not serializable"; concat: "Function is not serializable"; ... 46 more ...; [BRAND]: { ...; }; }; } | Promise<...>'.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
How can I avoid this error when I use Branded Types?
Here is a minimal reproduce-able code :
And the error is:
Argument of type '() => { id: string & z.BRAND<"FooId">; }' is not assignable to parameter of type 'ServerFn<"GET", undefined, undefined, { id: string & BRAND<"FooId">; }>'. Type '{ id: string & BRAND<"FooId">; }' is not assignable to type '{ id: { readonly [x: number]: string; toString: "Function is not serializable"; charAt: "Function is not serializable"; charCodeAt: "Function is not serializable"; concat: "Function is not serializable"; ... 46 more ...; [BRAND]: { ...; }; }; } | Promise<...>'.
Any thoughts?
Beta Was this translation helpful? Give feedback.
All reactions