0
0
mirror of https://github.com/honojs/hono.git synced 2024-11-21 18:18:57 +01:00

perf(types): use homomorphic mapped type to reduce conditional branches (#3440)

This commit is contained in:
m-shaka 2024-09-23 15:22:17 +09:00 committed by GitHub
parent 1d8028a70d
commit e1eb98d293
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -52,14 +52,8 @@ export type JSONParsed<T> = T extends { toJSON(): infer J }
? T
: T extends InvalidJSONValue
? never
: T extends []
? []
: T extends readonly [infer R, ...infer U]
? [JSONParsed<InvalidToNull<R>>, ...JSONParsed<U>]
: T extends Array<infer U>
? Array<JSONParsed<InvalidToNull<U>>>
: T extends ReadonlyArray<infer U>
? ReadonlyArray<JSONParsed<InvalidToNull<U>>>
: T extends ReadonlyArray<unknown>
? { [K in keyof T]: JSONParsed<InvalidToNull<T[K]>> }
: T extends Set<unknown> | Map<unknown, unknown>
? {}
: T extends object