Skip to content

Commit

Permalink
TS compilation perf: faster objectUtil.addQuestionMarks
Browse files Browse the repository at this point in the history
I'm not sure what the precise reasons for this being faster are,
but consistently benchmarking in my project about 50% more type
instantiations with the original version vs. the one proposed in
this commit; plus the compilation time is 20% longer in the original.
  • Loading branch information
jussisaurio committed Oct 6, 2023
1 parent 481c9ba commit 2ff8a1e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion deno/lib/helpers/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ export namespace objectUtil {
T extends object,
R extends keyof T = requiredKeys<T>
// O extends keyof T = optionalKeys<T>
> = Pick<Required<T>, R> & Partial<T>;
> = Required<T> extends infer Strict
? { [K in R]: K extends keyof Strict ? Strict[K] : never } & {
[K in keyof T]?: T[K];
}
: never;
// = { [k in O]?: T[k] } & { [k in R]: T[k] };

export type identity<T> = T;
Expand Down
6 changes: 5 additions & 1 deletion src/helpers/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ export namespace objectUtil {
T extends object,
R extends keyof T = requiredKeys<T>
// O extends keyof T = optionalKeys<T>
> = Pick<Required<T>, R> & Partial<T>;
> = Required<T> extends infer Strict
? { [K in R]: K extends keyof Strict ? Strict[K] : never } & {
[K in keyof T]?: T[K];
}
: never;
// = { [k in O]?: T[k] } & { [k in R]: T[k] };

export type identity<T> = T;
Expand Down

0 comments on commit 2ff8a1e

Please sign in to comment.