Table of Contents
Using keyOf for references
What is keyOf?
The `s.keyOf()` schema type creates a reference to keys from a another Val module that is defined using `s.record()`. This enables safe references between your content, ensuring that links and references always point to existing content.
Setting up referenceable content
In order to refer to content using keyOf, you must first have a `s.record` to which you want to refer.
In the example below, we have defined a module of all authors by email.
Refering to content using keyOf
When you have a record of keys that you want to refer to, use s.keyOf. This will make it possible for content editors to select from a list of possible options, the keys of the record. It will also make it possible for Val to validate the reference.
Recursive keyOf
When using keyOf, you might end up in a situation where you have mutally recursive schemas. A consequence of this is that typescript will no longer be able to infer the types of the modules that are mutally recursive.
This can occour when you use the page router.
To avoid this, you can use the "getter syntax" on all keyOf related types.
By using the the "getter syntax" you are now able to use the linkButton in the blogs / support article pages.