Skip to content

Commit

Permalink
Optimize object strip case (#1393)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Sep 11, 2022
1 parent 6011b67 commit 033088d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion deno/lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ dateSchema.safeParse(new Date("1/12/22")); // success: true
dateSchema.safeParse("2022-01-12T00:00:00.000Z"); // success: true
```

## Zod enums-
## Zod enums

```ts
const FishEnum = z.enum(["Salmon", "Tuna", "Trout"]);
Expand Down
14 changes: 11 additions & 3 deletions deno/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1669,9 +1669,17 @@ export class ZodObject<

const { shape, keys: shapeKeys } = this._getCached();
const extraKeys: string[] = [];
for (const key in ctx.data) {
if (!shapeKeys.includes(key)) {
extraKeys.push(key);

if (
!(
this._def.catchall instanceof ZodNever &&
this._def.unknownKeys === "strip"
)
) {
for (const key in ctx.data) {
if (!shapeKeys.includes(key)) {
extraKeys.push(key);
}
}
}

Expand Down
14 changes: 11 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1669,9 +1669,17 @@ export class ZodObject<

const { shape, keys: shapeKeys } = this._getCached();
const extraKeys: string[] = [];
for (const key in ctx.data) {
if (!shapeKeys.includes(key)) {
extraKeys.push(key);

if (
!(
this._def.catchall instanceof ZodNever &&
this._def.unknownKeys === "strip"
)
) {
for (const key in ctx.data) {
if (!shapeKeys.includes(key)) {
extraKeys.push(key);
}
}
}

Expand Down

0 comments on commit 033088d

Please sign in to comment.