import { ShorthandConfig } from '@fluentui/react-bindings'; import * as React from 'react'; import { ShorthandFactory } from './utils/factories'; // ======================================================== // Utilities // ======================================================== export type ResultOf = T extends (...arg: any[]) => infer TResult ? TResult : never; export type ObjectOf = { [key: string]: T }; export type Omit = Pick>; // ======================================================== // Components // ======================================================== export type FluentComponentStaticProps

= { handledProps: (keyof P)[]; create?: ShorthandFactory

; shorthandConfig?: ShorthandConfig

; }; // ======================================================== // Props // ======================================================== export type Props = T & ObjectOf; export type ReactChildren = React.ReactNodeArray | React.ReactNode; export type ComponentEventHandler = (event: React.SyntheticEvent, data?: TProps) => void; export type ComponentKeyboardEventHandler = (event: React.KeyboardEvent, data?: TProps) => void; export type InstanceOf = T extends { new (...args: any[]): infer TInstance } ? TInstance : never; export type PropsOf = T extends React.Component ? TProps : T extends React.FunctionComponent ? TProps : T extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[T] : never; // ======================================================== // Shorthand Factories // ======================================================== export type ShorthandRenderFunction

= (Component: React.ElementType

, props: P) => React.ReactNode; // The ReactFragment here is replaced from the original typings with ReactNodeArray because of incorrect inheriting of the type when it is defined as {} type ReactNode = React.ReactChild | React.ReactNodeArray | React.ReactPortal | boolean | null | undefined; export type ShorthandValue

= ReactNode | ObjectShorthandValue

; type KindSelector = { [P in keyof T]: { kind?: P } & T[P]; }[keyof T]; export type ShorthandCollection> = ShorthandValue< Props | (KindSelector & Props) >[]; export type ObjectShorthandValue

= Props

& { children?: P['children'] | ShorthandRenderFunction

; }; export type ObjectShorthandCollection = ObjectShorthandValue

[];