From 4262b63bed7306b4bd67d568bd0808056a2f5e53 Mon Sep 17 00:00:00 2001 From: Mathias Andresen Date: Thu, 28 Mar 2024 10:38:08 +0100 Subject: [PATCH] Fix typings for EditorComponentField (#7160) * fix: make EditorComponentField type handle widget='list' correctly * fix: make field and fields optional for widget='list' --------- Co-authored-by: Anze Demsar --- packages/decap-cms-core/index.d.ts | 31 +++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/packages/decap-cms-core/index.d.ts b/packages/decap-cms-core/index.d.ts index 7cf7d97cc839..9eb5e7f9855e 100644 --- a/packages/decap-cms-core/index.d.ts +++ b/packages/decap-cms-core/index.d.ts @@ -409,19 +409,24 @@ declare module 'decap-cms-core' { config: CmsConfig; } - export interface EditorComponentField { - name: string; - label: string; - widget: string; - /** - * Used if widget === "list" to create a flat array - */ - field: EditorComponentField; - /** - * Used if widget === "list" to create an array of objects - */ - fields: EditorComponentField[]; - } + export type EditorComponentField = + | ({ + name: string; + label: string; + } & { + widget: Omit; + }) + | { + widget: 'list'; + /** + * Used if widget === "list" to create a flat array + */ + field?: EditorComponentField; + /** + * Used if widget === "list" to create an array of objects + */ + fields?: EditorComponentField[]; + }; export interface EditorComponentOptions { id: string;