diff --git a/packages/api-headless-cms/src/plugins/CmsModelPlugin.ts b/packages/api-headless-cms/src/plugins/CmsModelPlugin.ts index ec46c94c9fc..63100ac9c60 100644 --- a/packages/api-headless-cms/src/plugins/CmsModelPlugin.ts +++ b/packages/api-headless-cms/src/plugins/CmsModelPlugin.ts @@ -32,7 +32,7 @@ interface CmsModelFieldInput extends Omit { isPrivate?: never; - noValidate?: never; + noValidate?: boolean; singularApiName?: string; pluralApiName?: string; fields: CmsModelFieldInput[]; } -export interface CmsApiModelFull extends Omit { - noValidate: true; +export interface CmsApiModelFull extends Omit { fields: CmsModelFieldBase[]; } @@ -70,7 +69,7 @@ interface CmsPrivateModel | "titleFieldId" | "description" > { - noValidate?: never; + noValidate?: boolean; titleFieldId?: string; singularApiName?: never; pluralApiName?: never; @@ -78,9 +77,9 @@ interface CmsPrivateModel fields: CmsModelFieldInput[]; } -export interface CmsPrivateModelFull extends Omit { +export interface CmsPrivateModelFull + extends Omit { fields: CmsModelFieldBase[]; - noValidate: true; } export type CmsModelInput = CmsApiModel | CmsPrivateModel | CmsApiModelFull | CmsPrivateModelFull; @@ -139,12 +138,13 @@ export class CmsModelPlugin extends Plugin { /** * We can safely ignore this error, because we are sure noValidate is not a model field. */ - // @ts-expect-error delete input["noValidate"]; return { ...modelPlugin, ...input, + // Since `noValidate` is set, we trust the input, and cast to `CmsModelFieldBase`. + fields: input.fields as CmsModelFieldBase[], pluralApiName, singularApiName }; @@ -341,16 +341,16 @@ export const createCmsModel = ( }; export const createPrivateModel = ( - input: Omit + input: Omit ): CmsPrivateModelFull => { return { authorization: false, - ...input, - isPrivate: true, noValidate: true, + isPrivate: true, group: { id: "private", name: "Private Models" - } + }, + ...input }; };