payload icon indicating copy to clipboard operation
payload copied to clipboard

plugin-form-builder: Type error when adding fields to existing blocks

Open blobmold opened this issue 1 year ago • 2 comments

I am encountering a type error whenever I am trying to extend existing blocks.

import { fields } from '@payloadcms/plugin-form-builder';

formBuilder({
    fields: {
        select: {
            ...fields.select,
            fields: [
                ...fields.select.fields,
                {
                    name: 'hasMultiple',
                    label: 'Has Multiple',
                    type: 'checkbox',
                    defaultValue: false,
                },
            ],
        },
    },
}),

This is the error I am getting: Property 'fields' does not exist on type 'Block | ((fieldConfig?: boolean | FieldConfig) => Block)'. Property 'fields' does not exist on type '(fieldConfig?: boolean | FieldConfig) => Block'.ts(2339)

blobmold avatar Nov 07 '23 08:11 blobmold

it will work if you do a casting of the field as Block (fields.select as Block)

select: {
            ...fields.select,
            fields: [
                ...(fields.select as Block).fields,
                {
                    name: 'hasMultiple',
                    label: 'Has Multiple',
                    type: 'checkbox',
                    defaultValue: false,
                },
            ],
        },

supermario12342003 avatar Nov 22 '23 16:11 supermario12342003

This plugin is now being maintained in the Packages Directory of the Payload Monorepo. This repo will soon be archived and all open issues be closed. This issue, however, will be transferred over. Please refer to this open discussion for more details.

jacobsfletch avatar Dec 12 '23 21:12 jacobsfletch