Skip to content

draft: true doesn’t prevent TypeScript from expecting required fields #12578

@GermanJablo

Description

@GermanJablo

Describe the Bug

According to the documentation, draft: true prevents mandatory fields from having to be defined, but TypeScript requires them anyway:

https://payloadcms.com/docs/versions/drafts#updating-or-creating-drafts

Link to the code that reproduces this issue

https://github.com/payloadcms/payload

Reproduction Steps

  1. In test/_community/collections/Posts/index.ts, add versions: { drafts: true } to the collection and required: true to the "content" field.
  2. Run pnpm dev to generate the types.
  3. You'll see an error in the second payload.create of the file: test/_community/config.ts. This error appears even if you add draft: true as a property to payload.create:
Type '{ title: string; }' is not assignable to type 'Omit<Post, "id" | "sizes" | "createdAt" | "updatedAt"> & Partial<Pick<Post, "id" | "sizes" | "createdAt" | "updatedAt">>'.
Property 'content' is missing in type '{ title: string; }' but required in type 'Omit<Post, "id" | "sizes" | "createdAt" | "updatedAt">'.ts(2322)

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

area: core

Environment Info

Payload: 3.39.1

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions