payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
25.67k stars 1.63k forks source link

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

Open blobmold opened 1 year ago

blobmold commented 1 year ago

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)

supermario12342003 commented 12 months ago

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,
                },
            ],
        },
jacobsfletch commented 11 months ago

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.