Skip to content

Latest commit

History

History
30 lines (23 loc) 路 664 Bytes

readme.md

File metadata and controls

30 lines (23 loc) 路 664 Bytes

number

Back to root readme.md

This function uses the rulr.isNumber guard to check the input is a number as shown in the example below. It should only throw rulr.InvalidNumberError. You might want to consider constraining numbers somehow to avoid display and storage bugs.

import * as rulr from 'rulr'

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

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

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

// Invalid
const example2: Example = constrainToExample({
	example: '1',
})