Ts For Core
No security coverage
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
- Add this repogitory git url to the devDependencies using Node.js package manager like yarn or npm.
npm i -D git+ssh://[email protected]:project/ts_for_core.git#VERSION
- Configure TypeScript module settings to tsconfig.json like below.
- Add import type statement on your TypeScript code to load the Drupal core TypeScript definition. The library definition is almost same as
core.libraries.ymldefinition 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
>
}
}
}
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
Release Timeline
Releases
| Version | Type | Core | Notes | Release date | |
|---|---|---|---|---|---|
| 0.1.0 | Stable | Support for Drupal 11 only. Add drupal.htmx definition for Drupal 11. | Dec 10, 2025 | ||
| 0.0.3 | Stable | Fix add_css ajax command parameter type. | Dec 1, 2025 | ||
| 0.0.2 | Stable | Drupal 11 and Drupal 10 are supported | Sep 12, 2025 | ||
| 0.1.x-dev | Dev | Sep 12, 2025 | |||
| 0.0.1 | Stable | The first release | Jan 20, 2025 | ||
| 0.0.x-dev | Dev | Jan 16, 2025 |