From 8b35612df23f2a4c5b5c5ccfd8bb25d93698f5df Mon Sep 17 00:00:00 2001 From: dwightjack Date: Wed, 6 Oct 2021 19:35:24 +0900 Subject: [PATCH] fix: oneOfType native check resolution --- __tests__/validators/oneoftype.test.ts | 5 +++++ src/validators/oneoftype.ts | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/__tests__/validators/oneoftype.test.ts b/__tests__/validators/oneoftype.test.ts index 6a0f1bd9..8c1571b6 100644 --- a/__tests__/validators/oneoftype.test.ts +++ b/__tests__/validators/oneoftype.test.ts @@ -45,6 +45,11 @@ describe('`.oneOfType`', () => { expect(validator({ id: '10' })).toBe(false) }) + it('should extract native types from other validators', () => { + const type = oneOfType([string(), integer()]) + expect(type.type).toEqual([String, Number]) + }) + it('should validate multiple shapes', () => { const customType = oneOfType([ shape({ diff --git a/src/validators/oneoftype.ts b/src/validators/oneoftype.ts index 798315e3..6c55923e 100644 --- a/src/validators/oneoftype.ts +++ b/src/validators/oneoftype.ts @@ -42,12 +42,12 @@ export default function oneOfType< if (type.type === true || !type.type) { warn('oneOfType - invalid usage of "true" or "null" as types.') continue - } - if (type.type) { + } else { nativeChecks = nativeChecks.concat(type.type) } + } else { + nativeChecks.push(type as Prop) } - nativeChecks.push(type as Prop) } // filter duplicates