Skip to main content
The @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 to createAgent, 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 your createAgent call:
  • typingsPath, where to write the generated file (e.g. './typings.ts')
  • typingsMaxDepth, how deep to introspect relationships (default 5 is usually sufficient)
The file is generated automatically on back-end startup. Do not edit it manually, it will be overwritten on the next restart.

TypeScript setup

In your customization files, import both CollectionCustomizer and your Schema:
The 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.
In customization files:

What gets autocompleted

Once the schema is typed, your IDE provides autocompletion for:

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, type orders. 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 typingsPath is set in your createAgent call
  • Check that the back-end starts without errors, introspection failures prevent typings generation
  • Verify the directory in typingsPath exists (e.g. if you set './src/typings.ts', the src/ 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 to createAgent
  • Try restarting your TypeScript language server in your IDE (VS Code: Cmd+Shift+P → “Restart TS Server”)

Type errors after a schema change

The typings file is regenerated on back-end restart. If you added or removed fields and see type errors, restart your back-end and the typings will update automatically.