Skip to content

Commit

Permalink
forgot to run yarn build:deno.
Browse files Browse the repository at this point in the history
  • Loading branch information
igalklebanov committed Nov 16, 2022
1 parent 95104bf commit bd0c300
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
5 changes: 3 additions & 2 deletions deno/lib/__tests__/pickomit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ test("nonstrict inference", () => {
});

test("nonstrict parsing - pass", () => {
const laxfish = fish.nonstrict().pick({ name: true });
const laxfish = fish.passthrough().pick({ name: true });
laxfish.parse({ name: "asdf", whatever: "asdf" });
laxfish.parse({ name: "asdf", age: 12, nested: {} });
});

test("nonstrict parsing - fail", () => {
const laxfish = fish.nonstrict().pick({ name: true });
const laxfish = fish.passthrough().pick({ name: true });
const bad = () => laxfish.parse({ whatever: "asdf" } as any);
expect(bad).toThrow();
});
Expand All @@ -85,6 +85,7 @@ test("pick a nonexistent key", () => {

const pickedSchema = schema.pick({
a: true,
// @ts-expect-error
doesntExist: true,
});

Expand Down
14 changes: 10 additions & 4 deletions deno/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1772,6 +1772,12 @@ export type SomeZodObject = ZodObject<
any
>;

export type objectKeyMask<Obj> = { [k in keyof Obj]?: true };

export type optionalPickWith<Obj, Shape> = {
[k in keyof Obj]?: k extends keyof Shape ? Obj[k] : never;
};

function deepPartialify(schema: ZodTypeAny): any {
if (schema instanceof ZodObject) {
const newShape: any = {};
Expand Down Expand Up @@ -2015,8 +2021,8 @@ export class ZodObject<
}) as any;
}

pick<Mask extends { [k in keyof T]?: true }>(
mask: Mask
pick<Mask extends objectKeyMask<T>>(
mask: optionalPickWith<Mask, objectKeyMask<T>>
): ZodObject<Pick<T, Extract<keyof T, keyof Mask>>, UnknownKeys, Catchall> {
const shape: any = {};
util.objectKeys(mask).map((key) => {
Expand All @@ -2029,8 +2035,8 @@ export class ZodObject<
}) as any;
}

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

0 comments on commit bd0c300

Please sign in to comment.