next-drupal icon indicating copy to clipboard operation
next-drupal copied to clipboard

DrupalNode type definition missing body

Open violabg opened this issue 3 years ago • 1 comments

DrupalNode type definition is missing the body prop

violabg avatar Aug 06 '22 14:08 violabg

Hi. Thanks for the feedback.

The reason we don't have a body field on the DrupalNode is because not all node types have a body field.

Example we have some node types using paragraphs and we generally remove the body field.

With that said, you can extend the interface and add your own field pretty easily.

import { DrupalNode } from "next-drupal"


export interface ArticleNode extends DrupalNode {
  body: {
    value: string
    processed: string
    format: string
  }
  field_another_field: string
}

Then you can use it as follows:

const article = await drupal.getResource<ArticleNode>("node--article", ID)

// No error.
article.body.processed

Hope this helps.

shadcn avatar Aug 08 '22 06:08 shadcn

Could you provide better documentation about this? I didn't know where to put and how to use what is "explained" under Extending Types at https://next-drupal.org/docs/typescript

kopeboy avatar Oct 27 '23 12:10 kopeboy