From 024257cf171f7432e106da0672c7c8b6cb612f29 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Wed, 30 Mar 2022 09:02:38 -0400 Subject: [PATCH] Faster extra keys detection --- deno/lib/types.ts | 8 ++++++-- src/types.ts | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/deno/lib/types.ts b/deno/lib/types.ts index 80d69b897..d1975fc1a 100644 --- a/deno/lib/types.ts +++ b/deno/lib/types.ts @@ -1558,8 +1558,12 @@ export class ZodObject< const { status, ctx } = this._processInputParams(input); const { shape, keys: shapeKeys } = this._getCached(); - const dataKeys = util.objectKeys(ctx.data); - const extraKeys = dataKeys.filter((k) => !shapeKeys.includes(k)); + const extraKeys: string[] = []; + for (const key in ctx.data) { + if (!shapeKeys.includes(key)) { + extraKeys.push(key); + } + } const pairs: { key: ParseReturnType; diff --git a/src/types.ts b/src/types.ts index 79dfbb40c..8e1985cc7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1558,8 +1558,12 @@ export class ZodObject< const { status, ctx } = this._processInputParams(input); const { shape, keys: shapeKeys } = this._getCached(); - const dataKeys = util.objectKeys(ctx.data); - const extraKeys = dataKeys.filter((k) => !shapeKeys.includes(k)); + const extraKeys: string[] = []; + for (const key in ctx.data) { + if (!shapeKeys.includes(key)) { + extraKeys.push(key); + } + } const pairs: { key: ParseReturnType;