TypeScript

Using built-in types with DrupalClient.


Every helper method for the DrupalClient has full TypeScript support.

The next-drupal module ships with some default basic types you can use.


Built-in Types

DrupalNode

export interface DrupalNode extends JsonApiResourceWithPath {
drupal_internal__nid: number
drupal_internal__vid: number
changed: string
created: string
title: string
default_langcode: boolean
sticky: boolean
}

DrupalBlock

export interface DrupalBlock extends JsonApiResource {
info: string
}

DrupalMedia

export interface DrupalMedia extends JsonApiResource {
drupal_internal__mid: string
drupal_internal__vid: string
changed: string
created: string
name: string
}

DrupalFile

export interface DrupalFile extends JsonApiResource {
drupal_internal__fid: string
changed: string
created: string
filename: string
uri: {
value: string
url: string
}
filesize: number
filemime: string
resourceIdObjMeta?: DrupalFileMeta
}
export interface DrupalFileMeta {
alt?: string
title?: string
width: number
height: number
}

DrupalTaxonomyTerm

export interface DrupalTaxonomyTerm extends JsonApiResourceWithPath {
drupal_internal__tid: string
changed: string
default_langcode: boolean
name: string
description: string
weight: number
}

DrupalUser

export interface DrupalUser extends JsonApiResourceWithPath {
drupal_internal__uid: string
changed: string
created: string
default_langcode: boolean
name: string
}

DrupalView

/* eslint-disable @typescript-eslint/no-explicit-any */
export interface DrupalView<T = Record<string, any>[]> {
id: string
results: T
meta: JsonApiResponse["meta"]
links: JsonApiResponse["links"]
}

DrupalParagraph

export interface DrupalParagraph extends JsonApiResource {
drupal_internal__id: number
drupal_internal__revision_id: number
}

PathAlias

export type PathAlias = {
alias: string
pid: number
langcode: string
}

DrupalMenuLinkContent

export interface DrupalMenuLinkContent {
description: string
enabled: boolean
expanded: boolean
id: string
menu_name: string
meta: Record<string, unknown>
options: Record<string, unknown>
parent: string
provider: string
route: {
name: string
parameters: Record<string, unknown>
}
title: string
type: string
url: string
weight: string
items?: DrupalMenuLinkContent[]
}

DrupalTranslatedPath

export interface DrupalTranslatedPath {
resolved: string
isHomePath: boolean
entity: {
canonical: string
type: string
bundle: string
id: string
uuid: string
langcode?: string
}
label?: string
jsonapi?: {
individual: string
resourceName: string
pathPrefix: string
basePath: string
entryPoint: string
}
meta?: Record<string, unknown>
redirect?: {
from: string
to: string
status: string
}[]
}

Extending Types

To extend the built-in types, create a file at types/drupal.d.ts and extend the types as follows.

types/drupal.d.ts

interface Article extends DrupalNode {
field_foo: string
}