Skip to content

Commit

Permalink
fix: fix .pick(), .omit() generic Type (#3255)
Browse files Browse the repository at this point in the history
  • Loading branch information
petrovmiroslav authored Apr 8, 2024
1 parent 565ba1a commit 1d2bc9b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions deno/lib/helpers/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export namespace util {
export type OmitKeys<T, K extends string> = Pick<T, Exclude<keyof T, K>>;
export type MakePartial<T, K extends keyof T> = Omit<T, K> &
Partial<Pick<T, K>>;
export type Exactly<T, X> = T & Record<Exclude<keyof X, keyof T>, never>;

export const arrayToEnum = <T extends string, U extends [T, ...T[]]>(
items: U
Expand Down
4 changes: 2 additions & 2 deletions deno/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2675,7 +2675,7 @@ export class ZodObject<
}) as any;
}

pick<Mask extends { [k in keyof T]?: true }>(
pick<Mask extends util.Exactly<{ [k in keyof T]?: true }, Mask>>(
mask: Mask
): ZodObject<Pick<T, Extract<keyof T, keyof Mask>>, UnknownKeys, Catchall> {
const shape: any = {};
Expand All @@ -2692,7 +2692,7 @@ export class ZodObject<
}) as any;
}

omit<Mask extends { [k in keyof T]?: true }>(
omit<Mask extends util.Exactly<{ [k in keyof T]?: true }, Mask>>(
mask: Mask
): ZodObject<Omit<T, keyof Mask>, UnknownKeys, Catchall> {
const shape: any = {};
Expand Down
1 change: 1 addition & 0 deletions src/helpers/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export namespace util {
export type OmitKeys<T, K extends string> = Pick<T, Exclude<keyof T, K>>;
export type MakePartial<T, K extends keyof T> = Omit<T, K> &
Partial<Pick<T, K>>;
export type Exactly<T, X> = T & Record<Exclude<keyof X, keyof T>, never>;

export const arrayToEnum = <T extends string, U extends [T, ...T[]]>(
items: U
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2676,7 +2676,7 @@ export class ZodObject<
}) as any;
}

pick<Mask extends { [k in keyof T]?: true }>(
pick<Mask extends util.Exactly<{ [k in keyof T]?: true }, Mask>>(
mask: Mask
): ZodObject<Pick<T, Extract<keyof T, keyof Mask>>, UnknownKeys, Catchall> {
const shape: any = {};
Expand All @@ -2693,7 +2693,7 @@ export class ZodObject<
}) as any;
}

omit<Mask extends { [k in keyof T]?: true }>(
omit<Mask extends util.Exactly<{ [k in keyof T]?: true }, Mask>>(
mask: Mask
): ZodObject<Omit<T, keyof Mask>, UnknownKeys, Catchall> {
const shape: any = {};
Expand Down

0 comments on commit 1d2bc9b

Please sign in to comment.