Skip to content

Latest commit

 

History

History
23 lines (18 loc) · 504 Bytes

recursiveRules.md

File metadata and controls

23 lines (18 loc) · 504 Bytes

Recursive Rules

Back to root readme.md

To create a recursive rule in Rulr, you simply create a new rule as a function and reference it within itself as shown below.

function constrainToExample(input: unknown) {
	return rulr.object({
		optional: {
			optional: constrainToExample,
		},
	})(input)
}

type Example = rulr.Static<typeof constrainToExample>
// {
//   optional?: Example
// }

// Valid
const example: Example = constrainToExample({ optional: { optional: {} } })