From 385895112b899f692c57bb976b460cb69699a047 Mon Sep 17 00:00:00 2001 From: Aria Minaei Date: Fri, 17 Sep 2021 15:41:39 +0200 Subject: [PATCH] More arg validation rules --- theatre/core/src/propTypes/index.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/theatre/core/src/propTypes/index.ts b/theatre/core/src/propTypes/index.ts index 81ec872..0701025 100644 --- a/theatre/core/src/propTypes/index.ts +++ b/theatre/core/src/propTypes/index.ts @@ -157,9 +157,16 @@ export const number = ( `opts.range in t.number(defaultValue, opts) must have two elements. ${opts.range.length} given.`, ) } - if (!opts.range.every((n) => typeof n === 'number' && isFinite(n))) { + if (!opts.range.every((n) => typeof n === 'number' && !isNaN(n))) { throw new Error( - `opts.range in t.number(defaultValue, opts) must be a tuple of two finite numbers.`, + `opts.range in t.number(defaultValue, opts) must be a tuple of two numbers.`, + ) + } + if (opts.range[0] >= opts.range[1]) { + throw new Error( + `opts.range[0] in t.number(defaultValue, opts) must be smaller than opts.range[1]. Given: ${JSON.stringify( + opts.range, + )}`, ) } }