@forestadmin/agent package is written in TypeScript and ships with complete type definitions. With a small amount of setup, you get autocompletion for collection names, field names, and all customization APIs, in both TypeScript and JavaScript projects.
How it works
Forest generates a typings file from your data model. This file contains TypeScript interfaces that describe each collection and its fields. Once generated, you pass this schema as a generic type parameter tocreateAgent, which propagates the types throughout all your customization code.
The result: your IDE knows that the orders collection has a total_amount field of type number, and will autocomplete accordingly.
Generating the typings file
Add two options to yourcreateAgent call:
typingsPath, where to write the generated file (e.g.'./typings.ts')typingsMaxDepth, how deep to introspect relationships (default5is usually sufficient)
TypeScript setup
CollectionCustomizer and your Schema:
customizeCollection call is strongly typed, the second argument ('orders') is validated against your actual collection names, and the handler receives a fully-typed CollectionCustomizer.
JavaScript setup (with JSDoc)
If your project uses JavaScript, get autocompletion using JSDoc type annotations. The pattern uses@typedef to import types from the generated typings file.
What gets autocompleted
Once the schema is typed, your IDE provides autocompletion for:| Context | What’s autocompleted |
|---|---|
customizeCollection('...') | Collection names from your database |
addField, removeField, renameField | Field names within the collection |
dependencies: [...] | Field names available as dependencies |
getValues record parameter | Field values with correct types |
Action context (.form, .record) | Field names and types in action handlers |
| Filter conditions | Field names for Smart Segment and scope filters |
IDE configuration
VS Code
TypeScript and JSDoc autocompletion work out of the box with the built-in TypeScript language server. No additional extensions are required. To verify it’s working: open a customization file, typeorders. and you should see a list of available methods. Inside a dependencies array, type a quote and you should see field name suggestions.
WebStorm / IntelliJ
WebStorm has built-in TypeScript support. Open your project and the IDE will automatically pick up the typings file. JSDoc-based autocompletion also works without additional configuration.Troubleshooting
The typings file isn’t being generated
- Make sure
typingsPathis set in yourcreateAgentcall - Check that the back-end starts without errors, introspection failures prevent typings generation
- Verify the directory in
typingsPathexists (e.g. if you set'./src/typings.ts', thesrc/directory must exist)
Collection names aren’t being suggested
- Confirm the typings file exists and isn’t empty
- Make sure you’re passing
<Schema>as the generic tocreateAgent - Try restarting your TypeScript language server in your IDE (VS Code: Cmd+Shift+P → “Restart TS Server”)