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.

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

default discord avatar
twoxic2 years 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
    2 years ago
    @399871533276987392

    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
    absolutegravitaslast year

    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
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.