diff --git a/packages/remix-server-runtime/jsonify.ts b/packages/remix-server-runtime/jsonify.ts index 80a6c2b5afd..80e69589ad5 100644 --- a/packages/remix-server-runtime/jsonify.ts +++ b/packages/remix-server-runtime/jsonify.ts @@ -13,7 +13,7 @@ export type Jsonify = IsAny extends true ? any : // toJSON - T extends { toJSON(): infer U } ? (U extends JsonValue ? U : unknown) : + T extends { toJSON(): infer U } ? (U extends JsonValue ? U : Jsonify) : // primitives T extends JsonPrimitive ? T : @@ -46,7 +46,7 @@ export type Jsonify = // value is always not JSON => true // value is always JSON => false -// value is somtimes JSON, sometimes not JSON => boolean +// value is sometimes JSON, sometimes not JSON => boolean // note: cannot be inlined as logic requires union distribution type ValueIsNotJson = T extends NotJson ? true : false; @@ -146,8 +146,14 @@ type _tests = [ // toJson Expect, "stuff">>, Expect, string>>, - Expect, unknown>>, - Expect, unknown>>, + Expect, never>>, + Expect, string>>, + Expect }>, EmptyObject>>, + Expect, Record>>, + Expect, [1, "two", string, null, false]>>, + Expect, [unknown, 1]>>, + // @ts-expect-error + Expect, {a: string}>>, Expect, string>>, @@ -161,13 +167,27 @@ type _tests = [ // object Expect>, {}>>, Expect>, {a: string}>>, + Expect>, {a: string}>>, + Expect}>>, {a: EmptyObject}>>, + Expect>, {a: Record}>>, + Expect>, {a: [1, "two", string, null, false]}>>, + Expect>, {a: [unknown, 1]}>>, + // @ts-expect-error + Expect>, {a: {a: string}}>>, Expect>, {a?: string}>>, Expect>, {a?: string}>>, + Expect>, {a?: string}>>, + Expect}>>, {a?: EmptyObject}>>, + Expect>, {a?: Record}>>, + Expect>, {a?: [1, "two", string, null, false]}>>, + Expect>, {a?: [unknown, 1]}>>, + // @ts-expect-error + Expect>, {a?: {a: string}}>>, Expect>, {a: string, b?: string}>>, Expect>, {}>>, Expect>>, Record>>, Expect>>, Record>>, - Expect}>, { payload: Record}>>, + Expect}>, {payload: Record}>>, Expect