Skip to content

Commit

Permalink
perf(types): use homomorphic mapped type to reduce conditional branch…
Browse files Browse the repository at this point in the history
…es (#3440)
  • Loading branch information
m-shaka authored Sep 23, 2024
1 parent 1d8028a commit e1eb98d
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e1eb98d

Please sign in to comment.