payload
payload copied to clipboard
`draft: true` doesn’t prevent TypeScript from expecting required fields
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
- In
test/_community/collections/Posts/index.ts, addversions: { drafts: true }to the collection andrequired: trueto the "content" field. - Run
pnpm devto generate the types. - You'll see an error in the second
payload.createof the file:test/_community/config.ts. This error appears even if you adddraft: trueas a property topayload.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