Skip to content

Typescript: Object literal may only specify known properties, and 'min' does not exist in type #6800

@kidroca

Description

@kidroca

Describe the bug

If we define a relation field with multiple: true and min or max we get the following typescript typings error

Object literal may only specify known properties, and 'min' does not exist in type '(CmsFieldBase & CmsFieldRelation) | (CmsFieldBase & CmsFieldMeta)'.

To Reproduce

  1. Have a project using Typescript
  2. Have your CMS schema defined in typescript

Sample code:

import CMS from 'netlify-cms-app';

const local_backend = process.env.NODE_ENV === 'development';

CMS.init({
  config: {
    local_backend,
    load_config_file: false,
    backend: {
      name: 'git-gateway',
      branch: 'main',
    },
    collections: [
      {
        name: 'pages',
        label: 'Pages',
        folder: 'cms/content/pages',
        create: false,
        slug: '{{slug}}',
        fields: [
          {
            label: 'Fund Types',
            name: 'fundTypes',
            widget: 'relation',
            collection: 'Options',
            search_fields: ['label'],
            value_field: 'label',
            multiple: true,
            min: 1, // we get the error here
          },
        ],
      },
    ],
  },
});

Expected behavior

No typescript error should occur, because min and max are valid relation properties

Screenshots

Applicable Versions:

  • "netlify-cms-app": "^2.15.72",

CMS configuration

import CMS from 'netlify-cms-app';

const local_backend = process.env.NODE_ENV === 'development';

CMS.init({
  config: {
    local_backend,
    load_config_file: false,
    backend: {
      name: 'git-gateway',
      branch: 'main',
    },
    collections: [
      {
        name: 'pages',
        label: 'Pages',
        folder: 'cms/content/pages',
        create: false,
        slug: '{{slug}}',
        fields: [
          {
            label: 'Fund Types',
            name: 'fundTypes',
            widget: 'relation',
            collection: 'Options',
            search_fields: ['label'],
            value_field: 'label',
            multiple: true,
            min: 1, // we get the error here
          },
        ],
      },
    ],
  },
});

Additional context

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions