Skip to content

Commit

Permalink
fix(dev): only apply pretty types for objects
Browse files Browse the repository at this point in the history
  • Loading branch information
pcattori committed Jun 10, 2023
1 parent b662d41 commit 12c7075
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/remix-server-runtime/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { TypedDeferredData, TypedResponse } from "./responses";

// force Typescript to simplify the type
type Pretty<T> = { [K in keyof T]: T[K] } & {};
type PrettyTransform<T, U> = [T] extends [U] ? T : Pretty<U>;

type JsonPrimitive =
| string
Expand All @@ -21,7 +22,7 @@ type NonJsonPrimitive = undefined | Function | symbol;
type IsAny<T> = 0 extends 1 & T ? true : false;

// prettier-ignore
type Serialize<T> = Pretty<
type Serialize<T> =
IsAny<T> extends true ? any :
T extends TypedDeferredData<infer U> ? SerializeDeferred<U> :
T extends JsonPrimitive ? T :
Expand All @@ -30,9 +31,9 @@ type Serialize<T> = Pretty<
T extends [] ? [] :
T extends [unknown, ...unknown[]] ? SerializeTuple<T> :
T extends ReadonlyArray<infer U> ? (U extends NonJsonPrimitive ? null : Serialize<U>)[] :
T extends object ? SerializeObject<UndefinedToOptional<T>> :
T extends object ? PrettyTransform<T, SerializeObject<UndefinedToOptional<T>>> :
never
>;
;

/** JSON serialize [tuples](https://www.typescriptlang.org/docs/handbook/2/objects.html#tuple-types) */
type SerializeTuple<T extends [unknown, ...unknown[]]> = {
Expand Down

0 comments on commit 12c7075

Please sign in to comment.