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!
@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
.
hi this is old but now also affects Orders (i.e. the template-ecommerce git)... occurring in
maybe related to this?
https://github.com/payloadcms/payload/issues/2009Star
Discord
online
Get help straight from the Payload team with an Enterprise License.