Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imported fields not generating interfaces #9668

Open
Patrickroelofs opened this issue Dec 2, 2024 · 0 comments
Open

Imported fields not generating interfaces #9668

Patrickroelofs opened this issue Dec 2, 2024 · 0 comments
Assignees
Labels

Comments

@Patrickroelofs
Copy link

Describe the Bug

The issue appears when you want to export a field into a seperate file, here for example I have exported my Icon field into a seperate file, importing it where needed. However, when running generate:types it does not generate the type for this field, although it should have by giving it the interfaceName.

import { deepMerge, type Field } from 'payload';
import { icons } from '@phosphor-icons/core';

type iconField = (overrides?: Partial<Field>) => Field;

export const iconField: iconField = (overrides = {}) =>
  deepMerge(
    {
      name: 'icon',
      label: 'Icon',
      type: 'select',
      interfaceName: 'Icons',
      options: icons.map((icon) => icon.pascal_name),
      required: true,
    },
    overrides,
  );

Here is an example of how the iconField is imported.

import { type GlobalConfig } from 'payload';
import { iconField } from '@/payload/fields/icons';

export const SiteSettings: GlobalConfig = {
  slug: 'site-settings',
  label: 'Site Settings',
  fields: [
    {
      name: 'socialMediaLinks',
      label: 'Social Media Links',
      type: 'array',
      fields: [
        iconField(),
        ...
      ],
    },
  ],
};

Here is a screenshot of the "socialMediaLinks" in the file payload-types.ts
Image

Link to the code that reproduces this issue

https://github.com/Patrickroelofs/patrickroelofs.com/blob/main/src/payload/fields/icons.ts

Reproduction Steps

  • Export a Field into a seperate file, say an icon field
  • Give this field an interfaceName
  • Import it into your GlobalConfig/Block/Collection
  • Running generate:types will not create the type as defined by interfaceName

An exported field will not generate types:

import { deepMerge, type Field } from 'payload';
import { icons } from '@phosphor-icons/core';

type iconField = (overrides?: Partial<Field>) => Field;

export const iconField: iconField = (overrides = {}) =>
  deepMerge(
    {
      name: 'icon',
      label: 'Icon',
      type: 'select',
      interfaceName: 'Icons',
      options: icons.map((icon) => icon.pascal_name),
      required: true,
    },
    overrides,
  );

Which area(s) are affected? (Select all that apply)

area: core

Environment Info

Binaries:
  Node: 23.1.0
  npm: N/A
  Yarn: N/A
  pnpm: 9.12.3
Relevant Packages:
  payload: 3.2.2
  next: 15.0.3
  @payloadcms/db-postgres: 3.2.2
  @payloadcms/graphql: 3.2.2
  @payloadcms/live-preview: 3.2.2
  @payloadcms/live-preview-react: 3.2.2
  @payloadcms/next/utilities: 3.2.2
  @payloadcms/plugin-cloud-storage: 3.2.2
  @payloadcms/richtext-lexical: 3.2.2
  @payloadcms/storage-vercel-blob: 3.2.2
  @payloadcms/translations: 3.2.2
  @payloadcms/ui/shared: 3.2.2
  react: 19.0.0-rc-fb9a90fa48-20240614
  react-dom: 19.0.0-rc-fb9a90fa48-20240614
Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Home
  Available memory (MB): 31863
  Available CPU cores: 16
@Patrickroelofs Patrickroelofs added status: needs-triage Possible bug which hasn't been reproduced yet validate-reproduction labels Dec 2, 2024
@github-actions github-actions bot added the stale label Jan 2, 2025
@paulpopus paulpopus self-assigned this Feb 3, 2025
@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants