Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). Varbase Media Header 9.2.1 Minor update available for module varbase_media_header (9.2.1). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

Ts For Core

No security coverage
View on drupal.org

This project provides TypeScript definitions for Drupal frontend development, allowing developers to use TypeScript with Drupal core's JavaScript APIs. It supports type checking for Drupal settings, AJAX commands, and theme functions.

This project provides Drupal core TypeScript definitions for Drupal frontend developing.

Supporting Drupal core version

Drupal 10, Drupal 11

How to use

  1. Add this repogitory git url to the devDependencies using Node.js package manager like yarn or npm.
  2. Configure TypeScript module settings to tsconfig.json like below.
  3. Add import type statement on your TypeScript code to load the Drupal core TypeScript definition. The library definition is almost same as core.libraries.yml definition but drupalSettings and once.js are not same. See below example code.

Example tsconfig.json:

{
  "compilerOptions": {
    "module": "ESNext",
    "moduleResolution": "Bundler",
}

Example code:

// Import each library definition.
import type {} from 'ts_for_core/drupal';
import type {} from 'ts_for_core/drupal.ajax';

// The drupalSettings and once.js definitions are not same as the core library definitions.
import type {} from 'ts_for_core/drupal_settings';
import type {} from 'ts_for_core/@drupal__once'

Actually used project

Extends Drupal specific type

drupalSettings

declare global {
  namespace drupalSettings {
    const someVariable: string|number
  }
}

/*
 * If there is no export/import in a d.ts file, TS2669 error occurs by TypeScript.
 * See https://stackoverflow.com/questions/57132428/augmentations-for-the-global-scope-can-only-be-directly-nested-in-external-modul.
 */
export type {}

Drupal.theme

declare global {
  namespace Drupal {
    namespace theme {
      let someTheme: (arg1: string) => HTMLElement
    }
  }
}

export type {}

A behavior with additional properties

declare global {
  namespace Drupal {
    interface behaviorAdditionalPropsMap {
      someBehavior : {
        additionalProp: Array<string>
      }
    }
  }
}

export type {}

AjaxCommand

import type { ajaxCommand } from "drupal.ajax"

declare global {
  namespace Drupal {
    interface definedAjaxCommands {
      someCommand: ajaxCommand<
        'someCommand',
        {
          arg1: number,
          arg2: boolean,
        },
        string
      >
    }
  }
}

Activity

Total releases
6
First release
Jan 2025
Latest release
7 months ago
Releases (12 mo)
4 ▲ from 2
Maintenance
Slowing

Release Timeline

Releases

Version Type Release date
0.1.0 Stable Dec 10, 2025
0.0.3 Stable Dec 1, 2025
0.0.2 Stable Sep 12, 2025
0.1.x-dev Dev Sep 12, 2025
0.0.1 Stable Jan 20, 2025
0.0.x-dev Dev Jan 16, 2025