Skip to main content
Node.js only - This page covers TypeScript autocompletion setup for the Node.js agent. For information about Forest data types, see Data Types.
The Forest Node.js back-end, built entirely in TypeScript, provides comprehensive autocompletion capabilities for collection names, field names, and handler parameters.

Generating a Typing File

The back-end can generate a typing file based on your data models. This file is auto-generated and should not be manually edited.

Configuration Options

Two configuration options control typing file generation:
  • typingsPath: Specifies the location where the typing file will be created
  • typingsMaxDepth: Controls the maximum introspection depth for relationships

TypeScript Usage

In TypeScript projects, import and template the generated schema:
import { createAgent } from '@forestadmin/agent';
import { Schema } from './typings';
import transactions from './customization/transactions';

await createAgent<Schema>({
  // ...
  typingsPath: './typings.ts',
  typingsMaxDepth: 5,
})
  .customizeCollection('transactions', transactions)
  .mountOnStandaloneServer(3000)
  .start();
The customizeCollection method and handler parameters receive strong typing through the Schema template.

JavaScript Usage

JavaScript developers can leverage JSDoc syntax to maintain autocomplete capabilities:

Main Back-end File

const { createAgent } = require('@forestadmin/agent');

/**
 * @typedef {import('@forestadmin/agent').Agent} Agent
 * @typedef {import('../typings').Schema} Schema
 */

/**
 * @type {Agent<Schema>}
 */
const agent = createAgent({
  typingsPath: './typings.ts',
  typingsMaxDepth: 5,
});

Customization Files

In separate customization files, JSDoc type annotations preserve autocompletion:
/**
 * @param {CollectionCustomizer<Schema, 'transactions'>} transactions
 */
module.exports = transactions => {
  transactions.removeField('amountInEur');
};