A CLI to generate TypeScript types for your directus schema.
npm install directus-ts-typegen

A CLI that automatically generates TypeScript types for your Directus schema, making it easier to work with your Directus data in a type-safe manner.
This CLI features support for O2M (One-to-Many), M2O (Many-to-One), M2M (Many-to-Many), and M2A (Many-to-Any) relations.
``bash`
npm install -g directus-ts-typegen
`bash`
npm install --save-dev directus-ts-typegen
`bash`
npx directus-ts-typegen
When you run the CLI without all required options, it will prompt you interactively:
`bash`
npx directus-ts-typegen
The CLI will ask for:
- Directus instance URL (with connectivity validation)
- Authentication method (email/password or static token)
- Credentials based on your chosen auth method
- Output file location (optional - defaults to stdout)
- Confirmation before overwriting existing files
`bash`
npx directus-ts-typegen [options]
- --directus-host: Host address of your directus instance
- --directus-email: Email address of your directus admin user
- --directus-password: Password of your directus admin user
- --directus-token: Static token of your directus admin user
- --output: Location of the file the types will be written to. If not set, types output to stdout
- --required-not-nullable: Treat required fields as non-nullable (omit null from their types)--type-prefix
- : Prefix to prepend to generated type names--type-suffix
- : Suffix to append to generated type names--type-style
- : Output style for type declarations (interface or type, default: interface)
These options can also be set using environment variables:
`bash`
DIRECTUS_TS_TYPEGEN_HOST=https://your-directus.com
DIRECTUS_TS_TYPEGEN_PASSWORD=yourpassword
DIRECTUS_TS_TYPEGEN_EMAIL=admin@example.com
DIRECTUS_TS_TYPEGEN_TOKEN=your-static-token
DIRECTUS_TS_TYPEGEN_OUTPUT=./types/directus.ts
The CLI supports two authentication methods to access your Directus instance:
`bash`
npx directus-ts-typegen --directus-host https://your-directus.com --directus-email admin@example.com --directus-password yourpassword
`bash``
npx directus-ts-typegen --directus-host https://your-directus.com --directus-token your-static-token
> Note: Static tokens are recommended for CI/CD environments and automated workflows.
Published under the MIT License.
---
_Need help or found a bug? Please open an issue on the project repository._