From 9c62c0525dabac6b80769075a35fa21eedb4241a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20St=C3=BCrmer?= Date: Fri, 19 Jan 2018 13:19:19 +0100 Subject: [PATCH 1/3] Fix EuiContextMenu types The types in EuiContextMenu caused errors that seemed to result from usage of the `Omit<>` helper. It might be fixed with https://github.com/Microsoft/TypeScript/issues/21148, which is expected to be included in 2.7.1. --- src/components/context_menu/index.d.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/components/context_menu/index.d.ts b/src/components/context_menu/index.d.ts index bde99cac903..7f35793029f 100644 --- a/src/components/context_menu/index.d.ts +++ b/src/components/context_menu/index.d.ts @@ -75,13 +75,12 @@ declare module '@elastic/eui' { export type EuiContextMenuPanelId = string | number; - export type EuiContextMenuPanelItemDescriptor = Omit< - EuiContextMenuItemProps, - 'hasPanel' - > & { + export interface EuiContextMenuPanelItemDescriptor + extends EuiContextMenuItemProps { + hasPanel?: never; name: string; panel?: EuiContextMenuPanelId; - }; + } interface EuiContextMenuPanelDescriptor { id: EuiContextMenuPanelId; @@ -96,7 +95,6 @@ declare module '@elastic/eui' { } export const EuiContextMenu: SFC< - Omit, 'className' | 'style'> & - EuiContextMenuProps + CommonProps & HTMLAttributes & EuiContextMenuProps >; } From 56ba5ddefac95e5677c029048533040217a601b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20St=C3=BCrmer?= Date: Fri, 19 Jan 2018 19:45:48 +0100 Subject: [PATCH 2/3] Use a more robust implementation of `Omit` The previous implementation of the `Omit` type did not support optional and readonly fields, which led to type errors when using the components. --- src/components/common.d.ts | 2 +- src/components/context_menu/index.d.ts | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/components/common.d.ts b/src/components/common.d.ts index b33923198f3..421701062ec 100644 --- a/src/components/common.d.ts +++ b/src/components/common.d.ts @@ -18,5 +18,5 @@ declare module '@elastic/eui' { type Diff = ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T]; - type Omit = { [P in Diff]: T[P] }; + type Omit = Pick>; } diff --git a/src/components/context_menu/index.d.ts b/src/components/context_menu/index.d.ts index 7f35793029f..c1d716701c2 100644 --- a/src/components/context_menu/index.d.ts +++ b/src/components/context_menu/index.d.ts @@ -75,12 +75,13 @@ declare module '@elastic/eui' { export type EuiContextMenuPanelId = string | number; - export interface EuiContextMenuPanelItemDescriptor - extends EuiContextMenuItemProps { - hasPanel?: never; + export type EuiContextMenuPanelItemDescriptor = Omit< + EuiContextMenuItemProps, + 'hasPanel' + > & { name: string; panel?: EuiContextMenuPanelId; - } + }; interface EuiContextMenuPanelDescriptor { id: EuiContextMenuPanelId; @@ -89,12 +90,11 @@ declare module '@elastic/eui' { content?: React.ReactNode; } - export interface EuiContextMenuProps { - panels?: EuiContextMenuPanelDescriptor[]; - initialPanelId?: EuiContextMenuPanelId; - } + export type EuiContextMenuProps = CommonProps & + Omit, 'style'> & { + panels?: EuiContextMenuPanelDescriptor[]; + initialPanelId?: EuiContextMenuPanelId; + }; - export const EuiContextMenu: SFC< - CommonProps & HTMLAttributes & EuiContextMenuProps - >; + export const EuiContextMenu: SFC; } From 9b769e719cb9a67e433cddd5ef3b2b2231c374d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20St=C3=BCrmer?= Date: Fri, 19 Jan 2018 13:25:50 +0100 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bf6bd2f9da..fe6f0bd9a54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ **Bug fixes** - Set `EuiFlexGroup` to `flex-grow: 1` to be more friendly with IE11 [(#315)](https://github.com/elastic/eui/pull/315) +- Fix TypeScript definitions such that optional and readonly properties survive being passed through `Omit` [(#322)](https://github.com/elastic/eui/pull/322) # [`0.0.13`](https://github.com/elastic/eui/tree/v0.0.13)