Skip to main content
drupalreleases
Release: Cms 2.2.3 — Update released for Drupal core (2.2.3)! Release: Easy Breadcrumb 2.0.11 — Minor update available for module easy_breadcrumb (2.0.11). Release: Bootstrap 8.x-3.42 — Minor update available for theme bootstrap (8.x-3.42). Release: Editoria11y Accessibility Checker 3.0.10 — Minor update available for module editoria11y (3.0.10). Release: Editoria11y Accessibility Checker 2.2.24 — Minor update available for module editoria11y (2.2.24). Release: Leaflet 10.4.13 — Minor update available for module leaflet (10.4.13). Release: Flag 5.1.1 — Minor update available for module flag (5.1.1). Release: Layout Paragraphs 3.0.0-beta5 — New beta version released for module layout_paragraphs (3.0.0-beta5). Module Revived: Bootstrap 8.x-3.41 — Theme bootstrap updated after 6 months of inactivity (8.x-3.41). Security Coverage: Component Library — Module component_library now has official Drupal security advisory coverage.

TypeScript Definition Generator

Security covered Drupal 11 · not 10
View on drupal.org

This module generates TypeScript type definitions for Drupal entities, and can optionally create functions to convert data between types. It is run via a Drush command using a configuration file.

Generates TypeScript type definitions from your site's own entity and field definitions, so a decoupled frontend describes Drupal's data by reading Drupal rather than by hand-maintaining interfaces that drift.

Choose which entity types to describe in the Drupal UI, then generate:

drush tsg --dir=../app/src/definitions --parser

Everything is derived from the Entity, Field and Typed Data APIs. Add a field
in Drupal, regenerate, and the compiler tells you what needs updating. Field
types the module has never heard of are described through their Typed Data
definitions rather than ignored, so a contributed field usually works without
anyone adding support for it.

What you can generate

Each output is opt-in, and all of them describe the same schema.

Drupal's payload shape is always written. It matches what the `serialization` module sends, wrappers and all.

title: FieldItemList<StringItem>

A frontend shape, and the functions producing it (`--normalized`,
`--parser`). The same content with the item wrappers removed, single values
collapsed, and references as pointers. The generated parsers are plain
functions, and the output imports nothing outside itself.

title: string | null
field_tags: EntityReferenceTaxonomyTermItem[]     // Ref<"taxonomy_term">

JSON:API (`--jsonapi`). A resource type per bundle, with attributes,
relationships narrowed to the resource types they can point at, and a document
that is a union of a data document and an error document, so reading `data`
without handling a failed request is a compile error. Sparse fieldsets have a
type too.

A bundle-to-component contract (`--components`). A map from every bundle to the component that renders it, so adding a bundle in Drupal stops the frontend compiling until someone assigns a component, rather than shipping a region nobody noticed was blank.

A language-neutral manifest (`--manifest`). `schema.json`, the same schema
as data rather than as types: field types, cardinality, allowed values, storage
classifications. For generating things this module does not, such as Zod
validators, JSON Schema, OpenAPI or documentation.

Works with most content entities

Definitions can be generated from nearly any content entity defined in your site. It also works with Layout Builder, Drupal Canvas, and Paragraphs.

Keeping definitions in sync

`--check` writes nothing and compares what would be generated against what is already there, exiting non-zero if they differ. Run it in CI against a site
installed from your committed configuration, and a field added without
regenerating fails the build instead of reaching production.

drush tsg --dir=../app/src/definitions --parser --check

Extending

Component generators are tagged services, so a contributed module can describe its own field types, or replace how a core one is described, by registering a generator at a higher priority. Generators receive the module's schema model rather than Drupal's managers.

The included `typescript_generator_metatag` submodule is a working example.

Requirements

Drupal 11 or 12, and Drush 13 or later.

The JSON:API output additionally needs the core `jsonapi` module. Nothing else is required, and the generated files have no runtime dependencies.

Upgrading from 3.x

4.0 is a rearchitecture. The YAML configuration file is gone in favor of Drupal
configuration and an admin form, the command takes its output directory as an option.

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
4
Tracked since
Jan 2024
Latest release
1 month ago
Releases (12 mo)
2 ▲ from 0
Maintenance
Active

Release Timeline

Releases

Version Type Core Release date
4.0.0 Stable 11 Aug 21, 2026
4.0.x-dev Dev 11 Aug 18, 2026
3.0.0-alpha1 Pre-release 10–11 Jun 21, 2024
3.0.x-dev Dev 10–11 Jan 20, 2024