Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Why does payload generate:types not include collection arrays?

default discord avatar
mrl72 years ago
2

We are getting a list of news items from payload using the rest API which returns the below JSON.



When we use the keyword

payload generate:types

it doesn't include a root type for the docs array.



We've managed to get around it by providing a news root type as shown below. Is there any way to not have to do this? We have a lot of collections of data we need to fetch.



News root type we have created


export interface NewsRoot {
  docs: News[]
}


News type generated by payload


export interface News {
  id: string;
  newsTitle: string;
  newsSubtitle?: string;
  tags?: string[] | Tag[];
  publishDate: string;
  newsBackgroundImage?: string | Media;
  newsDescription: {
    [k: string]: unknown;
  }[];
  createdAt: string;
  updatedAt: string;
}


News Response JSON


{
   "docs":[
      {
         "id":"63eadb6fa2e0dc97541772fd",
         "newsTitle":"Example News Post",
         "newsSubtitle":"Example subtitle ",
         "tags":[
            {
               "id":"63e97b49dbd275c70ad55f3a",
               "tagName":"Tag 1",
               "createdAt":"2023-02-12T23:50:33.844Z",
               "updatedAt":"2023-02-12T23:50:33.844Z"
            },
            {
               "id":"63e97a64a6d0765b19b75cd1",
               "tagName":"Tag 2",
               "createdAt":"2023-02-12T23:46:44.215Z",
               "updatedAt":"2023-02-12T23:46:44.215Z"
            }
         ],
         "publishDate":"2023-02-13T11:00:00.000Z",
         "newsDescription":[
            {
               "children":[
                  {
                     "text":"Example news post"
                  }
               ]
            }
         ],
         "createdAt":"2023-02-14T00:53:03.082Z",
         "updatedAt":"2023-02-15T03:57:21.638Z"
      }
   ],
   "totalDocs":1,
   "limit":10,
   "totalPages":1,
   "page":1,
   "pagingCounter":1,
   "hasPrevPage":false,
   "hasNextPage":false,
   "prevPage":null,
   "nextPage":null
}
  • default discord avatar
    jessrynkar2 years ago

    Hi

    @178109250806087680

    - we will definitely include this in our future updates to

    generate:types

    , I've made a note on a related github discussion that you can find here

    https://github.com/payloadcms/payload/discussions/2090
  • default discord avatar
    mrl72 years ago

    Thanks

    @854377910689202256

    . I will keep an eye out for a future update 🙂

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.