More arg validation rules
This commit is contained in:
parent
eb695a1c91
commit
385895112b
1 changed files with 9 additions and 2 deletions
|
@ -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,
|
||||
)}`,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue