Skip to content

Latest commit

 

History

History
35 lines (27 loc) · 751 Bytes

File metadata and controls

35 lines (27 loc) · 751 Bytes

negativeNumber

Back to root readme.md

This function uses the rulr.isNegativeNumber guard to check the input is a valid negativeNumber as shown in the example below. It should only throw rulr.InvalidNegativeNumberError.

import * as rulr from 'rulr'

const constrainToExample = rulr.object({
	required: {
		example: rulr.negativeNumber,
	},
})

type Example = rulr.Static<typeof constrainToExample>
// {
//   example: rulr.NegativeNumber
// }

// Valid
const example1: Example = constrainToExample({
	example: -1,
})

// Invalid: Not a valid NegativeNumber
const example2: Example = constrainToExample({
	example: 1,
})

// Invalid: Not a number
const example3: Example = constrainToExample({
	example: '-1',
})