diff --git a/src/components/common.ts b/src/components/common.ts index 8789e5c5aeb..2cb42f0d33d 100644 --- a/src/components/common.ts +++ b/src/components/common.ts @@ -1,3 +1,5 @@ +import { Component, FunctionComponent, SFC } from 'react'; + export interface CommonProps { className?: string; 'aria-label'?: string; @@ -18,6 +20,12 @@ export function keysOf(obj: T): K[] { return Object.keys(obj) as K[]; } +export type PropsOf = + C extends SFC ? SFCProps : + C extends FunctionComponent ? FunctionalProps : + C extends Component ? ComponentProps + : never; + /* TypeScript's discriminated unions are overly permissive: as long as one type of the union is satisfied the other types are not validated against. For example: diff --git a/src/components/tool_tip/index.d.ts b/src/components/tool_tip/index.d.ts index d4b76c0a272..bd02a8b9e7a 100644 --- a/src/components/tool_tip/index.d.ts +++ b/src/components/tool_tip/index.d.ts @@ -1,4 +1,6 @@ import { ReactElement, ReactNode, SFC } from 'react'; +import { EuiIcon } from '../icon'; +import { Omit, PropsOf } from '../common'; declare module '@elastic/eui' { export type ToolTipPositions = @@ -11,26 +13,23 @@ declare module '@elastic/eui' { | 'regular' | 'long'; - export interface ToolTipProps { + export interface EuiToolTipProps { + children: ReactElement; className?: string; - content: ReactNode; + content?: ReactNode; delay?: ToolTipDelay; title?: ReactNode; id?: string; position?: ToolTipPositions; } - - export interface EuiToolTipProps { - children: ReactElement; - } - export const EuiToolTip: SFC; + export const EuiToolTip: SFC; export interface EuiIconTipProps { color?: string; type?: string; size?: string; 'aria-label'?: string; - iconProps?: object; + iconProps?: PropsOf; } - export const EuiIconTip: SFC; + export const EuiIconTip: SFC & EuiIconTipProps>; }