Skip to content

Commit

Permalink
fix(server): constrain the IsRecord utility type to objects (#5081)
Browse files Browse the repository at this point in the history
  • Loading branch information
jussisaurio committed Nov 21, 2023
1 parent 3a57291 commit ec2ed1a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/server/src/shared/internal/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ type IsAny<T> = 0 extends T & 1 ? true : false;
// support it as both a Primitive and a NonJsonPrimitive
type JsonReturnable = JsonPrimitive | undefined;

type IsRecord<T> = keyof WithoutIndexSignature<T> extends never ? true : false;
type IsRecord<T extends object> = keyof WithoutIndexSignature<T> extends never
? true
: false;

/* prettier-ignore */
export type Serialize<T> =
Expand All @@ -31,8 +33,9 @@ export type Serialize<T> =
T extends [] ? [] :
T extends [unknown, ...unknown[]] ? SerializeTuple<T> :
T extends readonly (infer U)[] ? (U extends NonJsonPrimitive ? null : Serialize<U>)[] :
IsRecord<T> extends true ? Record<keyof T, Serialize<T[keyof T]>> :
T extends object ? Simplify<SerializeObject<UndefinedToOptional<T>>> :
T extends object ?
IsRecord<T> extends true ? Record<keyof T, Serialize<T[keyof T]>> :
Simplify<SerializeObject<UndefinedToOptional<T>>> :
never;

/** JSON serialize [tuples](https://www.typescriptlang.org/docs/handbook/2/objects.html#tuple-types) */
Expand Down

3 comments on commit ec2ed1a

@vercel
Copy link

@vercel vercel bot commented on ec2ed1a Nov 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

www – ./www

beta.trpc.io
trpc.io
www-git-main-trpc.vercel.app
www-trpc.vercel.app
alpha.trpc.io
www.trpc.io

@vercel
Copy link

@vercel vercel bot commented on ec2ed1a Nov 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

next-prisma-starter – ./examples/next-prisma-starter

next-prisma-starter-trpc.vercel.app
next-prisma-starter-git-main-trpc.vercel.app
nextjs.trpc.io

@vercel
Copy link

@vercel vercel bot commented on ec2ed1a Nov 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

og-image – ./www/og-image

og-image.trpc.io
og-image-git-main-trpc.vercel.app
og-image-trpc.vercel.app
og-image-three-neon.vercel.app

Please sign in to comment.