TypeScript

使用 DrupalClient 内置类型。


每个 DrupalClient 的辅助方法都具有完整的 TypeScript 支持。

next-drupal 模块附带了一些可供使用的默认基本类型。


内置类型

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
}

Drupal文件

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
}

Drupal分类术语

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

Drupal用户

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

Drupal视图

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

Drupal段落

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

路径别名

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

Drupal菜单链接内容

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[]
}

Drupal翻译后的路径

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
}[]
}

扩展类型

要扩展内置类型,请在 types/drupal.d.ts 文件中创建文件,并按如下方式扩展类型。

types/drupal.d.ts

interface Article extends DrupalNode {
field_foo: string
}