Skip to content

Commit

Permalink
Update source/jsonify.d.ts
Browse files Browse the repository at this point in the history
Co-authored-by: Pedro Cattori <pcattori@gmail.com>
  • Loading branch information
MichaelDeBoey and pcattori authored Jul 7, 2023
1 parent 6de5984 commit 6d83840
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions source/jsonify.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@ import type {IsAny} from './is-any';
// Note: The return value has to be `any` and not `unknown` so it can match `void`.
type NotJsonable = ((...arguments_: any[]) => any) | undefined | symbol;

type JsonifyTuple<T extends unknown[]> = T extends [infer F, ... infer R]
? [Jsonify<F>, ...Jsonify<R>]
: [];
type FilterNonNever<T extends unknown[]> = T extends [infer F, ...infer R]
? IsNever<F> extends true
? FilterNonNever<R>
: [F, ...FilterNonNever<R>]
: IsNever<T[number]> extends true
? []
: T;

// Handles tuples and arrays
type JsonifyList<T extends unknown[]> = T extends [infer F, ...infer R]
? FilterNonNever<[Jsonify<F>, ...JsonifyList<R>]>
: Array<Jsonify<T[number]>>;

type FilterJsonableKeys<T extends object> = {
[Key in keyof T]: T[Key] extends NotJsonable ? never : Key;
Expand Down

0 comments on commit 6d83840

Please sign in to comment.