From 643edf5b1c8a4e32d2f5a1e61cfa64dac6ba098d Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Tue, 1 Oct 2019 12:59:59 -0400 Subject: [PATCH] [react-select] Enforce OptionType should be an object (#38691) * Extend object * Keep the change * All the `OptionType`s * Formatting * Two space indentation --- types/react-select/src/Async.d.ts | 10 +++++----- types/react-select/src/AsyncCreatable.d.ts | 8 ++++---- types/react-select/src/Creatable.d.ts | 10 +++++----- types/react-select/src/Select.d.ts | 11 ++++++----- types/react-select/src/animated/MultiValue.d.ts | 5 +++-- types/react-select/src/animated/Placeholder.d.ts | 5 +++-- types/react-select/src/animated/SingleValue.d.ts | 5 +++-- .../react-select/src/animated/ValueContainer.d.ts | 5 +++-- types/react-select/src/animated/index.d.ts | 3 ++- types/react-select/src/builtins.d.ts | 10 +++++----- types/react-select/src/components/Control.d.ts | 4 ++-- types/react-select/src/components/Group.d.ts | 4 ++-- types/react-select/src/components/Menu.d.ts | 13 +++++++------ types/react-select/src/components/MultiValue.d.ts | 12 ++++++------ types/react-select/src/components/Option.d.ts | 4 ++-- types/react-select/src/components/Placeholder.d.ts | 4 ++-- types/react-select/src/components/SingleValue.d.ts | 6 +++--- types/react-select/src/components/containers.d.ts | 8 ++++---- types/react-select/src/components/index.d.ts | 13 +++++++------ types/react-select/src/components/indicators.d.ts | 6 +++--- types/react-select/src/stateManager.d.ts | 10 +++++----- types/react-select/src/types.d.ts | 14 +++++++++----- types/react-select/src/utils.d.ts | 3 ++- 23 files changed, 93 insertions(+), 80 deletions(-) diff --git a/types/react-select/src/Async.d.ts b/types/react-select/src/Async.d.ts index fb60802658..76f59d8f93 100644 --- a/types/react-select/src/Async.d.ts +++ b/types/react-select/src/Async.d.ts @@ -2,9 +2,9 @@ import * as React from 'react'; import Select, { Props as SelectProps } from './Select'; import { handleInputChange } from './utils'; import manageState from './stateManager'; -import { OptionsType, InputActionMeta } from './types'; +import { OptionsType, InputActionMeta, OptionTypeBase } from './types'; -export interface AsyncProps { +export interface AsyncProps { /* The default set of options to show before the user starts searching. When set to `true`, the results for loadOptions('') will be autoloaded. Default: false. */ @@ -18,11 +18,11 @@ export interface AsyncProps { cacheOptions?: any; } -export type Props = SelectProps & AsyncProps; +export type Props = SelectProps & AsyncProps; export const defaultProps: Props; -export interface State { +export interface State { defaultOptions?: OptionsType; inputValue: string; isLoading: boolean; @@ -31,7 +31,7 @@ export interface State { passEmptyOptions: boolean; } -export class Async extends React.Component, State> { +export class Async extends React.Component, State> { static defaultProps: Props; select: React.Ref; lastRequest: {}; diff --git a/types/react-select/src/AsyncCreatable.d.ts b/types/react-select/src/AsyncCreatable.d.ts index 749354a4a9..96e7c60df6 100644 --- a/types/react-select/src/AsyncCreatable.d.ts +++ b/types/react-select/src/AsyncCreatable.d.ts @@ -1,14 +1,14 @@ import { Component, Ref as ElementRef } from 'react'; import { Props as AsyncProps, State as AsyncState } from './Async'; import { Props as CreatableProps, State as CreatableState } from './Creatable'; -import { OptionsType, ValueType, ActionMeta, InputActionMeta } from './types'; +import { OptionsType, ValueType, ActionMeta, InputActionMeta, OptionTypeBase } from './types'; import { cleanValue } from './utils'; -export type Props = AsyncProps & CreatableProps; +export type Props = AsyncProps & CreatableProps; -export type State = AsyncState & CreatableState; +export type State = AsyncState & CreatableState; -export class AsyncCreatable extends Component, State> { +export class AsyncCreatable extends Component, State> { static defaultProps: Props; select: ElementRef; lastRequest: {}; diff --git a/types/react-select/src/Creatable.d.ts b/types/react-select/src/Creatable.d.ts index 5cae63021c..4dff380bc4 100644 --- a/types/react-select/src/Creatable.d.ts +++ b/types/react-select/src/Creatable.d.ts @@ -1,10 +1,10 @@ import * as React from 'react'; import Select, { Props as SelectProps } from './Select'; -import { OptionsType, ValueType, ActionMeta } from './types'; +import { OptionsType, ValueType, ActionMeta, OptionTypeBase } from './types'; import { cleanValue } from './utils'; import manageState from './stateManager'; -export interface CreatableProps { +export interface CreatableProps { /* Allow options to be created while the `isLoading` prop is true. Useful to prevent the "create new ..." option being displayed while async results are still being loaded. */ @@ -26,16 +26,16 @@ export interface CreatableProps { createOptionPosition?: 'first' | 'last'; } -export type Props = SelectProps & CreatableProps; +export type Props = SelectProps & CreatableProps; export const defaultProps: Props; -export interface State { +export interface State { newOption: OptionType | undefined; options: OptionsType; } -export class Creatable extends React.Component, State> { +export class Creatable extends React.Component, State> { static defaultProps: Props; select: React.Ref; diff --git a/types/react-select/src/Select.d.ts b/types/react-select/src/Select.d.ts index be3eff3fd4..31efacbb51 100644 --- a/types/react-select/src/Select.d.ts +++ b/types/react-select/src/Select.d.ts @@ -38,13 +38,14 @@ import { OptionsType, ValueType, GroupedOptionsType, + OptionTypeBase, } from './types'; export type MouseOrTouchEvent = | React.MouseEvent | React.TouchEvent; export type FormatOptionLabelContext = 'menu' | 'value'; -export interface FormatOptionLabelMeta { +export interface FormatOptionLabelMeta { context: FormatOptionLabelContext; inputValue: string; selectValue: ValueType; @@ -52,7 +53,7 @@ export interface FormatOptionLabelMeta { export type SelectComponentsProps = { [key in string]: any }; -export interface Props extends SelectComponentsProps { +export interface Props extends SelectComponentsProps { /* Aria label (for assistive tech) */ 'aria-label'?: string; /* HTML ID of an element that should be used as the label (for assistive tech) */ @@ -210,12 +211,12 @@ export interface Props extends Se export const defaultProps: Props; -export interface MenuOptions { +export interface MenuOptions { render: OptionType[]; focusable: OptionType[]; } -export interface State { +export interface State { ariaLiveSelection: string; ariaLiveContext: string; inputIsHidden: boolean; @@ -229,7 +230,7 @@ export interface State { export type ElRef = React.Ref; -export default class Select extends React.Component, State> { +export default class Select extends React.Component, State> { static defaultProps: Props; // Misc. Instance Properties diff --git a/types/react-select/src/animated/MultiValue.d.ts b/types/react-select/src/animated/MultiValue.d.ts index 8a8f37ad16..cbda6bdcc9 100644 --- a/types/react-select/src/animated/MultiValue.d.ts +++ b/types/react-select/src/animated/MultiValue.d.ts @@ -1,12 +1,13 @@ import { ComponentType } from 'react'; import { MultiValueProps } from '../components/MultiValue'; import { Collapse, fn } from './transitions'; +import { OptionTypeBase } from '../types'; -export type AnimatedMultiValueProps = { +export type AnimatedMultiValueProps = { in: boolean, onExited: fn, } & MultiValueProps; -export function AnimatedMultiValue(WrappedComponent: ComponentType>): ComponentType>; +export function AnimatedMultiValue(WrappedComponent: ComponentType>): ComponentType>; export default AnimatedMultiValue; diff --git a/types/react-select/src/animated/Placeholder.d.ts b/types/react-select/src/animated/Placeholder.d.ts index 1dbd3ba203..725d63d226 100644 --- a/types/react-select/src/animated/Placeholder.d.ts +++ b/types/react-select/src/animated/Placeholder.d.ts @@ -1,9 +1,10 @@ import { ComponentType } from 'react'; import { PlaceholderProps } from '../components/Placeholder'; import { Fade, collapseDuration } from './transitions'; +import { OptionTypeBase } from '../types'; -export type AnimatedPlaceholderProps = PlaceholderProps; +export type AnimatedPlaceholderProps = PlaceholderProps; -export function AnimatedPlaceholder(WrappedComponent: ComponentType>): ComponentType>; +export function AnimatedPlaceholder(WrappedComponent: ComponentType>): ComponentType>; export default AnimatedPlaceholder; diff --git a/types/react-select/src/animated/SingleValue.d.ts b/types/react-select/src/animated/SingleValue.d.ts index 6cd1bea908..0e9b5a73af 100644 --- a/types/react-select/src/animated/SingleValue.d.ts +++ b/types/react-select/src/animated/SingleValue.d.ts @@ -1,9 +1,10 @@ import { ComponentType } from 'react'; import { SingleValueProps } from '../components/SingleValue'; import { Fade } from './transitions'; +import { OptionTypeBase } from '../types'; -export type AnimatedSingleValueProps = SingleValueProps; +export type AnimatedSingleValueProps = SingleValueProps; -export function AnimatedSingleValue(WrappedComponent: ComponentType>): ComponentType>; +export function AnimatedSingleValue(WrappedComponent: ComponentType>): ComponentType>; export default AnimatedSingleValue; diff --git a/types/react-select/src/animated/ValueContainer.d.ts b/types/react-select/src/animated/ValueContainer.d.ts index 6bd15c0c19..ae5639570a 100644 --- a/types/react-select/src/animated/ValueContainer.d.ts +++ b/types/react-select/src/animated/ValueContainer.d.ts @@ -1,9 +1,10 @@ import { ComponentType } from 'react'; import { TransitionGroup } from 'react-transition-group'; import { ValueContainerProps } from '../components/containers'; +import { OptionTypeBase } from '../types'; -export type AnimatedValueContainerProps = ValueContainerProps; +export type AnimatedValueContainerProps = ValueContainerProps; -export function AnimatedValueContainer(WrappedComponent: ComponentType>): ComponentType>; +export function AnimatedValueContainer(WrappedComponent: ComponentType>): ComponentType>; export default AnimatedValueContainer; diff --git a/types/react-select/src/animated/index.d.ts b/types/react-select/src/animated/index.d.ts index c5180398b8..ae51c91fef 100644 --- a/types/react-select/src/animated/index.d.ts +++ b/types/react-select/src/animated/index.d.ts @@ -5,8 +5,9 @@ import { default as AnimatedMultiValue, AnimatedMultiValueProps } from './MultiV import { default as AnimatedPlaceholder, AnimatedPlaceholderProps } from './Placeholder'; import { default as AnimatedSingleValue, AnimatedSingleValueProps } from './SingleValue'; import { default as AnimatedValueContainer, AnimatedValueContainerProps } from './ValueContainer'; +import { OptionTypeBase } from '../types'; -export function makeAnimated(externalComponents?: SelectComponentsConfig): SelectComponents; +export function makeAnimated(externalComponents?: SelectComponentsConfig): SelectComponents; export const Input: ComponentType; export const MultiValue: ComponentType>; diff --git a/types/react-select/src/builtins.d.ts b/types/react-select/src/builtins.d.ts index 813d66ab9e..a53fecfe31 100644 --- a/types/react-select/src/builtins.d.ts +++ b/types/react-select/src/builtins.d.ts @@ -1,14 +1,14 @@ import { ReactNode } from 'react'; -import { GroupType } from './types'; +import { GroupType, OptionTypeBase } from './types'; -export type formatGroupLabel = (group: GroupType) => ReactNode; +export type formatGroupLabel = (group: GroupType) => ReactNode; export function formatGroupLabel(group: GroupType): ReactNode; -export type getOptionLabel = (option: OptionType) => string; +export type getOptionLabel = (option: OptionType) => string; export function getOptionLabel(option: any): string; -export type getOptionValue = (option: OptionType) => string; +export type getOptionValue = (option: OptionType) => string; export function getOptionValue(option: any): string; -export type isOptionDisabled = (option: OptionType) => boolean; +export type isOptionDisabled = (option: OptionType) => boolean; export function isOptionDisabled(option: any): boolean; diff --git a/types/react-select/src/components/Control.d.ts b/types/react-select/src/components/Control.d.ts index 8a9513197b..285f14ba64 100644 --- a/types/react-select/src/components/Control.d.ts +++ b/types/react-select/src/components/Control.d.ts @@ -1,7 +1,7 @@ import { ComponentType, ReactNode, Ref as ElementRef } from 'react'; import { borderRadius, colors, spacing } from '../theme'; -import { CommonProps, PropsWithStyles } from '../types'; +import { CommonProps, OptionTypeBase, PropsWithStyles } from '../types'; interface State { /** Whether the select is disabled. */ @@ -10,7 +10,7 @@ interface State { isFocused: boolean; } -export type ControlProps = CommonProps & +export type ControlProps = CommonProps & PropsWithStyles & State & { /** Children to render. */ diff --git a/types/react-select/src/components/Group.d.ts b/types/react-select/src/components/Group.d.ts index 39c3489bce..78d717b3e8 100644 --- a/types/react-select/src/components/Group.d.ts +++ b/types/react-select/src/components/Group.d.ts @@ -1,7 +1,7 @@ import { ReactNode, ComponentType } from 'react'; import { spacing } from '../theme'; -import { CommonProps } from '../types'; +import { CommonProps, OptionTypeBase } from '../types'; interface ComponentProps { /** The children to be rendered. */ @@ -11,7 +11,7 @@ interface ComponentProps { /** Label to be displayed in the heading component. */ label: ReactNode; } -export type GroupProps = CommonProps & ComponentProps; +export type GroupProps = CommonProps & ComponentProps; export function groupCSS(): React.CSSProperties; diff --git a/types/react-select/src/components/Menu.d.ts b/types/react-select/src/components/Menu.d.ts index 65dda94931..7f8c2f6b85 100644 --- a/types/react-select/src/components/Menu.d.ts +++ b/types/react-select/src/components/Menu.d.ts @@ -21,6 +21,7 @@ import { MenuPlacement, MenuPosition, CommonProps, + OptionTypeBase, } from '../types'; // ============================== @@ -45,7 +46,7 @@ export function getMenuPlacement(args: PlacementArgs): MenuState; // Menu Component // ------------------------------ -export type MenuProps = CommonProps & { +export type MenuProps = CommonProps & { /** The children to be rendered. */ children: ReactElement, /** Callback to update the portal after possible flip. */ @@ -66,7 +67,7 @@ export type MenuProps = CommonProps & { export function menuCSS(state: MenuState): React.CSSProperties; -export class Menu extends Component, MenuState> { +export class Menu extends Component, MenuState> { static contextTypes: { getPortalPlacement: (state: MenuState) => void, }; @@ -93,7 +94,7 @@ export interface MenuListProps { /** Inner ref to DOM Node */ innerRef: InnerRef; } -export type MenuListComponentProps = CommonProps & +export type MenuListComponentProps = CommonProps & MenuListProps & MenuListState; export function menuListCSS(state: MenuState): React.CSSProperties; @@ -106,7 +107,7 @@ export const MenuList: ComponentType>; export function noOptionsMessageCSS(): React.CSSProperties; export function loadingMessageCSS(): React.CSSProperties; -export type NoticeProps = CommonProps & { +export type NoticeProps = CommonProps & { /** The children to be rendered. */ children: ReactNode, /** Props to be passed on to the wrapper. */ @@ -127,7 +128,7 @@ export const LoadingMessage: ComponentType>; // Menu Portal // ============================== -export type MenuPortalProps = CommonProps & { +export type MenuPortalProps = CommonProps & { appendTo: HTMLElement, children: ReactNode, // ideally Menu controlElement: HTMLElement, @@ -145,7 +146,7 @@ interface PortalStyleArgs { export function menuPortalCSS(args: PortalStyleArgs): React.CSSProperties; -export class MenuPortal extends Component, MenuPortalState> { +export class MenuPortal extends Component, MenuPortalState> { static childContextTypes: { getPortalPlacement: (state: MenuState) => void, }; diff --git a/types/react-select/src/components/MultiValue.d.ts b/types/react-select/src/components/MultiValue.d.ts index 59974fbc46..1583d8d77f 100644 --- a/types/react-select/src/components/MultiValue.d.ts +++ b/types/react-select/src/components/MultiValue.d.ts @@ -1,9 +1,9 @@ import { ComponentType, Component, ReactNode } from 'react'; import { borderRadius, colors, spacing } from '../theme'; -import { CommonProps } from '../types'; +import { CommonProps, OptionTypeBase } from '../types'; -export type MultiValueProps = CommonProps &{ +export type MultiValueProps = CommonProps &{ children: ReactNode, components: any, cropWithEllipsis: boolean, @@ -22,7 +22,7 @@ export function multiValueCSS(): React.CSSProperties; export function multiValueLabelCSS(props: MultiValueProps): React.CSSProperties; export function multiValueRemoveCSS(props: MultiValueProps): React.CSSProperties; -export interface MultiValueGenericProps { +export interface MultiValueGenericProps { children: ReactNode; data: OptionType; innerProps: { className?: string }; @@ -32,7 +32,7 @@ export const MultiValueGeneric: ComponentType>; export const MultiValueContainer: typeof MultiValueGeneric; export const MultiValueLabel: typeof MultiValueGeneric; -export type MultiValueRemoveProps = CommonProps & { +export type MultiValueRemoveProps = CommonProps & { children: ReactNode, innerProps: { className: string, @@ -42,13 +42,13 @@ export type MultiValueRemoveProps = CommonProps & { }, selectProps: any, }; -export class MultiValueRemove extends Component> { +export class MultiValueRemove extends Component> { static defaultProps: { children: ReactNode, }; } -export class MultiValue extends Component> { +export class MultiValue extends Component> { static defaultProps: { cropWithEllipsis: boolean, }; diff --git a/types/react-select/src/components/Option.d.ts b/types/react-select/src/components/Option.d.ts index c770d91afa..bb148db849 100644 --- a/types/react-select/src/components/Option.d.ts +++ b/types/react-select/src/components/Option.d.ts @@ -1,7 +1,7 @@ import { ComponentType, ReactNode, MouseEventHandler } from 'react'; import { colors, spacing } from '../theme'; -import { CommonProps, PropsWithStyles, InnerRef } from '../types'; +import { CommonProps, PropsWithStyles, InnerRef, OptionTypeBase } from '../types'; interface State { /** Whether the option is disabled. */ @@ -19,7 +19,7 @@ interface InnerProps { onMouseOver: MouseEventHandler; tabIndex: number; } -export type OptionProps = PropsWithStyles & +export type OptionProps = PropsWithStyles & CommonProps & State & { /** The children to be rendered. */ diff --git a/types/react-select/src/components/Placeholder.d.ts b/types/react-select/src/components/Placeholder.d.ts index 1a72bd69a7..664956baca 100644 --- a/types/react-select/src/components/Placeholder.d.ts +++ b/types/react-select/src/components/Placeholder.d.ts @@ -1,9 +1,9 @@ import { ComponentType, ReactNode } from 'react'; import { colors, spacing } from '../theme'; -import { CommonProps } from '../types'; +import { CommonProps, OptionTypeBase } from '../types'; -export type PlaceholderProps = CommonProps & { +export type PlaceholderProps = CommonProps & { /** The children to be rendered. */ children: ReactNode, /** props passed to the wrapping element for the group. */ diff --git a/types/react-select/src/components/SingleValue.d.ts b/types/react-select/src/components/SingleValue.d.ts index bfb9cbca8c..2d5e45e8e3 100644 --- a/types/react-select/src/components/SingleValue.d.ts +++ b/types/react-select/src/components/SingleValue.d.ts @@ -1,12 +1,12 @@ import { ComponentType, ReactNode } from 'react'; import { colors, spacing } from '../theme'; -import { CommonProps } from '../types'; +import { CommonProps, OptionTypeBase } from '../types'; interface State { /** Whether this is disabled */ isDisabled: boolean; } -interface ValueProps { +interface ValueProps { /** The children to be rendered. */ children: ReactNode; /* The data of the selected option rendered in the Single Value componentn */ @@ -14,7 +14,7 @@ interface ValueProps { /** Props passed to the wrapping element for the group. */ innerProps: any; } -export type SingleValueProps = CommonProps & ValueProps & State; +export type SingleValueProps = CommonProps & ValueProps & State; export function css(props: SingleValueProps): React.CSSProperties; diff --git a/types/react-select/src/components/containers.d.ts b/types/react-select/src/components/containers.d.ts index c72609bf31..3a6907b015 100644 --- a/types/react-select/src/components/containers.d.ts +++ b/types/react-select/src/components/containers.d.ts @@ -1,6 +1,6 @@ import { Component, ReactNode, ComponentType } from 'react'; import { spacing } from '../theme'; -import { CommonProps, KeyboardEventHandler } from '../types'; +import { CommonProps, KeyboardEventHandler, OptionTypeBase } from '../types'; // ============================== // Root Container @@ -13,7 +13,7 @@ export interface ContainerState { isRtl: boolean; } -export type ContainerProps = CommonProps & +export type ContainerProps = CommonProps & ContainerState & { /** The children to be rendered. */ children: ReactNode, @@ -27,7 +27,7 @@ export const SelectContainer: ComponentType>; // Value Container // ============================== -export type ValueContainerProps = CommonProps & { +export type ValueContainerProps = CommonProps & { /** Set when the value container should hold multiple values */ isMulti: boolean, /** Whether the value container currently holds a value. */ @@ -47,7 +47,7 @@ export interface IndicatorsState { isRtl: boolean; } -export type IndicatorContainerProps = CommonProps & +export type IndicatorContainerProps = CommonProps & IndicatorsState & { /** The children to be rendered. */ children: ReactNode, diff --git a/types/react-select/src/components/index.d.ts b/types/react-select/src/components/index.d.ts index 1436336d26..cbba375561 100644 --- a/types/react-select/src/components/index.d.ts +++ b/types/react-select/src/components/index.d.ts @@ -43,15 +43,16 @@ import MultiValue, { import Option, { OptionProps } from './Option'; import Placeholder, { PlaceholderProps } from './Placeholder'; import SingleValue, { SingleValueProps } from './SingleValue'; +import { OptionTypeBase } from '../types'; -export type PlaceholderOrValue = +export type PlaceholderOrValue = | Element>> | Element>> | Array>>>; -export type IndicatorComponentType = ComponentType>; +export type IndicatorComponentType = ComponentType>; -export interface SelectComponents { +export interface SelectComponents { ClearIndicator: IndicatorComponentType | null; Control: ComponentType>; DropdownIndicator: IndicatorComponentType | null; @@ -79,12 +80,12 @@ export interface SelectComponents { ValueContainer: ComponentType>; } -export type SelectComponentsConfig = Partial>; +export type SelectComponentsConfig = Partial>; export const components: Required>; -export interface Props { +export interface Props { components: SelectComponentsConfig; } -export function defaultComponents(props: Props): SelectComponents; +export function defaultComponents(props: Props): SelectComponents; diff --git a/types/react-select/src/components/indicators.d.ts b/types/react-select/src/components/indicators.d.ts index 6bf74d1ff5..b5f4d97fde 100644 --- a/types/react-select/src/components/indicators.d.ts +++ b/types/react-select/src/components/indicators.d.ts @@ -1,7 +1,7 @@ import { ComponentType, ReactElement as ElementType } from 'react'; import { colors, spacing } from '../theme'; -import { CommonProps } from '../types'; +import { CommonProps, OptionTypeBase } from '../types'; // ============================== // Dropdown & Clear Icons @@ -14,7 +14,7 @@ export function DownChevron(props: any): any; // TODO svg type // Dropdown & Clear Buttons // ============================== -export type IndicatorProps = CommonProps & { +export type IndicatorProps = CommonProps & { /** The children to be rendered inside the indicator. */ children: ElementType, /** Props that will be passed on to the children. */ @@ -52,7 +52,7 @@ export function loadingIndicatorCSS(state: { size: number, }): React.CSSProperties; -export type LoadingIconProps = { +export type LoadingIconProps = { /** Props that will be passed on to the children. */ innerProps: any, /** The focused state of the select. */ diff --git a/types/react-select/src/stateManager.d.ts b/types/react-select/src/stateManager.d.ts index 13bdcffecf..c432711aa6 100644 --- a/types/react-select/src/stateManager.d.ts +++ b/types/react-select/src/stateManager.d.ts @@ -1,15 +1,15 @@ import { Component, ComponentType, Ref as ElementRef } from 'react'; import SelectBase, { Props as SelectProps } from './Select'; -import { ActionMeta, InputActionMeta, ValueType } from './types'; +import { ActionMeta, InputActionMeta, OptionTypeBase, ValueType } from './types'; -export interface DefaultProps { +export interface DefaultProps { defaultInputValue: string; defaultMenuIsOpen: boolean; defaultValue: ValueType; } -export interface Props { +export interface Props { defaultInputValue?: string; defaultMenuIsOpen?: boolean; defaultValue?: ValueType; @@ -29,7 +29,7 @@ type StateProps> = Pick>; -interface State { +interface State { inputValue: string; menuIsOpen: boolean; value: ValueType; @@ -38,7 +38,7 @@ interface State { type GetOptionType = T extends SelectBase ? OT : never; export class StateManager< - OptionType = { label: string; value: string }, + OptionType extends OptionTypeBase = { label: string; value: string }, T extends SelectBase = SelectBase > extends Component> & Props & SelectProps, State> { static defaultProps: DefaultProps; diff --git a/types/react-select/src/types.d.ts b/types/react-select/src/types.d.ts index a888fa43c6..bdcb407b7e 100644 --- a/types/react-select/src/types.d.ts +++ b/types/react-select/src/types.d.ts @@ -1,16 +1,20 @@ import * as React from 'react'; import { Props as SelectProps } from './Select'; -export type OptionsType = ReadonlyArray; +export interface OptionTypeBase { + [key: string]: any; +} -export interface GroupType { +export type OptionsType = ReadonlyArray; + +export interface GroupType { options: OptionsType; [key: string]: any; } -export type GroupedOptionsType = ReadonlyArray>; +export type GroupedOptionsType = ReadonlyArray>; -export type ValueType = OptionType | OptionsType | null | undefined; +export type ValueType = OptionType | OptionsType | null | undefined; export type FocusEventHandler = (event: React.FocusEvent) => void; export type MouseEventHandler = (event: React.MouseEvent) => void; @@ -34,7 +38,7 @@ export interface PropsWithStyles { export type ClassNameList = string[]; export type ClassNamesState = { [key: string]: boolean } | undefined; -export interface CommonProps { +export interface CommonProps { clearValue: () => void; className?: string; cx: (a: string | null, b: ClassNamesState | undefined, c: string | undefined) => string | void; diff --git a/types/react-select/src/utils.d.ts b/types/react-select/src/utils.d.ts index c907d59c2a..6a80593f69 100644 --- a/types/react-select/src/utils.d.ts +++ b/types/react-select/src/utils.d.ts @@ -3,6 +3,7 @@ import { ClassNamesState, InputActionMeta, OptionsType, + OptionTypeBase, ValueType, } from './types'; @@ -28,7 +29,7 @@ export function classNames( // Clean Value // ============================== -export function cleanValue(value: ValueType): OptionsType; +export function cleanValue(value: ValueType): OptionsType; // ============================== // Handle Input Change