Autocompletion & Typings
Since the Forest Admin agent is fully written in Typescript, every function has autocompletion capabilities. The agent can generate typing files based on your models.
This allows:
Autocompletion of collection names and fields
Typing validation on all your handlers (when using TypeScript)
Generate a typing file
The typing file generated by Forest Admin will allow you to autocomplete any given fields of a collection. This is an auto-generated file, so we highly suggest not editing it manually.
In the following sections, you can see that two options are given to the createAgent
function:
typingsPath
: The location you want your typing file to be created.typingsMaxDepth
: The maximum depth of introspection for relationships.
Using the typing file in a typescript context
In a typescript context, the usage of the typing file is pretty straightforward. You can simply import the typing file and template your createAgent
with the schema to use it.
You should be able to see that the customizeCollection
method is strongly typed, as well as the transactions
handler.
Using the typing file in a JavaScript context
You can still benefit from it in a Javascript environment by using the JSDoc syntax.
If you choose to split your customizeCollection
handler in a dedicated file (That's the project scaffolding we usually use at Forest Admin), you can use the following JSDoc example to keep the autocomplete experience intact.
Last updated