From 56528f1aced65aee1ba337d0100b8e6368772811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20G=C3=BCdelh=C3=B6fer?= Date: Thu, 22 Sep 2022 11:33:41 +0200 Subject: [PATCH 1/2] :rocket: From 208dd0d3f2f49f9b08bb7d404d0cd55a362c6129 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20G=C3=BCdelh=C3=B6fer?= Date: Thu, 22 Sep 2022 11:35:56 +0200 Subject: [PATCH 2/2] :rotatings_light: --- src/validators/object.ts | 14 +++++--------- test/validators/all.test.ts | 3 +-- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/validators/object.ts b/src/validators/object.ts index 00f33d9..79d5ea2 100644 --- a/src/validators/object.ts +++ b/src/validators/object.ts @@ -32,9 +32,7 @@ export type PropertiesValidatorResult = { * console.assert(validator({ age: 15, name: 'Kim' }) === undefined) * ``` */ -export function object< - V extends ValidatorMap, ->( +export function object( validatorMap: V, ): Validator, PropertiesValidatorResult> { return function objectValidator(subject, context) { @@ -44,12 +42,10 @@ export function object< const errorEntries = Object .keys(validatorMap) - .map((key) => - [ - key, - validatorMap[key](subject[key], context), - ] as const - ) + .map((key) => ([ + key, + validatorMap[key](subject[key], context), + ] as const)) .filter(([_, errors]) => errors !== undefined); if (errorEntries.length === 0) { diff --git a/test/validators/all.test.ts b/test/validators/all.test.ts index ded92ed..b2155a0 100644 --- a/test/validators/all.test.ts +++ b/test/validators/all.test.ts @@ -1,5 +1,4 @@ import { all } from "../../src/validators/all.ts"; -import { object } from "../../src/validators/object.ts"; import { allItems, is, @@ -61,7 +60,7 @@ Deno.test("should correctly type check with multiple validators", () => { Deno.test("should merge complicated errors correctly", () => { const validator = all( requiredPrimitive("date required"), - (value: number) => { + () => { return ["other date error"]; }, );