One of the biggest pain points when working with Search in React is that you have to write your own Typescript types for the entities that are returned from the API, which can be tedious and error-prone. Instead, we found a way to programmatically create these types based on your Search configuration!
This way, developers will get intellisense right in their IDE for search results’ fields, and subfields to insert without having to switch back and forth between their code and the API response, or remember details about the entity’s field configuration.
To utilize this feature, you can run the following commands:
# Start with this yext types generate answers --experienceKey YOUR_EXPERIENCE_KEY # Required --lang ts # Optional (default ts) /types # Optional [OUTPUT-DIR] (default /types)
Note that, by default, the command creates a new /types directory and fills it with the files, but you can override this by defining a different directory.
To learn more about Typescript Types in the Yext CLI, take a look at the Getting Started with the CLI - Managing Resources guide.