Typescript error on .create() of `upload collection`

default discord avatar
twoxic
7 months ago
2
const pMedia = await payload.create({
    collection: 'images',
    filePath: tmpFilePath,
    data: {
      name: 'name',
      alt: 'alt'
    }
  });


The above code works, but my IDE throws the following typescript error on the

data

property:


TS2322: Type '{ name: string; alt: string; }' is not assignable to type 'MarkOptional<Image, "id" | "updatedAt" | "createdAt">'.   Property 'sizes' is missing in type '{ name: string; alt: string; }' but required in type 'Omit<Image, "id" | "updatedAt" | "createdAt">'.


I copied the image collection from the docs (

https://payloadcms.com/docs/upload/overview

), I only added some

fields

. It looks like this:



const Images: CollectionConfig = {
  slug: 'images',
  access: {
    read: () => true
  },
  fields: [
    {
      name: 'name',
      type: 'text',
      required: true
    },
    {
      name: 'alt',
      type: 'text',
      required: true
    }
  ],
  upload: {
    staticURL: '/images',
    staticDir: imagesPath,
    imageSizes: [
      {
        name: 'thumbnail',
        width: 400,
        height: 300,
        position: 'centre'
      },
      {
        name: 'card',
        width: 768,
        height: 1024,
        position: 'centre'
      },
      {
        name: 'tablet',
        width: 1024,
        height: undefined,
        position: 'centre'
      }
    ],
    adminThumbnail: 'thumbnail',
    mimeTypes: ['image/*']
  }
};


Am I doing something wrong? Thanks in advance!



Hm. Looking at the documentation (

https://payloadcms.com/docs/upload/overview#image-sizes

) I gather that the

imageSizes

is used to automatically rescale the image (which it does). So why should I add

sizes

key to the

data

object? What is it used for?



Thanks for answering btw!

  • discord user avatar
    jarrod_not_jared
    Payload Team
    6 months ago

    @twoxic I believe you are correct, it is a TS issue and not related to the shape of data you are sending. Sizes is created for you and you should not need to send it - we just need to adjust our types on upload collections create/update to not require

    sizes

    .

  • default discord avatar
    absolutegravitas
    2 months ago

    hi this is old but now also affects Orders (i.e. the template-ecommerce git)... occurring in



    src/stripe/webhooks/invoiceCreatedOrUpdated.ts


    maybe related to this?

    https://github.com/payloadcms/payload/issues/2009
    image.png
Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.