#Block interface not being generated when field is defined directly

6 messages · Page 1 of 1 (latest)

solar niche
#

is the best practice with creating a simple Block (e.g one to show a bullet point list) to define the fields in the Block or create a separate collection for every block. Trying to define the fields in the Block seemed to not actually generate an interface:

import type { Block } from 'payload'

export const HeroBlock: Block = {
  slug: 'hero',
  interfaceName: 'HeroBlock',
  fields: [
    {
      name: 'title',
      type: 'text',
      required: true,
    },
    {
      name: 'subtitle',
      type: 'text',
    },
    {
      name: 'primaryButton',
      type: 'group',
      fields: [
        {
          name: 'text',
          type: 'text',
        },
        {
          name: 'link',
          type: 'text',
        }
      ]
    },
    {
      name: 'secondaryButton',
      type: 'group',
      fields: [
        {
          name: 'text',
          type: 'text',
        },
        {
          name: 'link',
          type: 'text',
        }
      ]
    }
  ]
} ```

This should have generated a HeroBlock interface from my understanding but running `pnpm payload generate:types` doesn't seem to do anything of the sort.
snow canyonBOT
somber fable
#

Is the block being used anywhere in your payload.config?

solar niche
#

ok weirdly it seems I ran pnpm payload generate:types again and it just worked I'm not sure if I did something but yeah I removed block from my payload.config.ts

somber fable
#

yeah the generated types come from your config, so if you have a block defined but not included in the payload config it will not be included in the types

solar niche
#

but it was in the Pages collection which is contained in the config file does it need to be in the actual file?