diff --git a/types/react-select/index.d.ts b/types/react-select/index.d.ts index 5906c96d6b..eae34b6905 100644 --- a/types/react-select/index.d.ts +++ b/types/react-select/index.d.ts @@ -17,20 +17,20 @@ export = ReactSelectClass; declare namespace ReactSelectClass { // Other components - class Creatable extends React.Component { } - class Async extends React.Component { } - class AsyncCreatable extends React.Component { } + class Creatable extends React.Component> { } + class Async extends React.Component> { } + class AsyncCreatable extends React.Component & ReactCreatableSelectProps> { } type HandlerRendererResult = JSX.Element | null | false; // Handlers - type FocusOptionHandler = (option: Option) => void; - type SelectValueHandler = (option: Option) => void; + type FocusOptionHandler = (option: Option) => void; + type SelectValueHandler = (option: Option) => void; type ArrowRendererHandler = (props: ArrowRendererProps) => HandlerRendererResult; - type FilterOptionHandler = (option: Option, filter: string) => Option; - type FilterOptionsHandler = (options: Options, filter: string, currentValues: Options) => Options; + type FilterOptionHandler = (option: Option, filter: string) => Option; + type FilterOptionsHandler = (options: Options, filter: string, currentValues: Options) => Options; type InputRendererHandler = (props: { [key: string]: any }) => HandlerRendererResult; - type MenuRendererHandler = (props: MenuRendererProps) => HandlerRendererResult; + type MenuRendererHandler = (props: MenuRendererProps) => HandlerRendererResult; type OnCloseHandler = () => void; type OnInputChangeHandler = (inputValue: string) => void; type OnInputKeyDownHandler = React.KeyboardEventHandler; @@ -38,27 +38,27 @@ declare namespace ReactSelectClass { type OnOpenHandler = () => void; type OnFocusHandler = React.FocusEventHandler; type OnBlurHandler = React.FocusEventHandler; - type OptionRendererHandler = (option: Option) => HandlerRendererResult; - type ValueRendererHandler = (option: Option) => HandlerRendererResult; + type OptionRendererHandler = (option: Option) => HandlerRendererResult; + type ValueRendererHandler = (option: Option) => HandlerRendererResult; type OnValueClickHandler = (value: string, event: React.MouseEvent) => void; - type IsOptionUniqueHandler = (arg: { option: Option, options: Options, labelKey: string, valueKey: string }) => boolean; + type IsOptionUniqueHandler = (arg: { option: Option, options: Options, labelKey: string, valueKey: string }) => boolean; type IsValidNewOptionHandler = (arg: { label: string }) => boolean; - type NewOptionCreatorHandler = (arg: { label: string, labelKey: string, valueKey: string }) => Option; + type NewOptionCreatorHandler = (arg: { label: string, labelKey: string, valueKey: string }) => Option; type PromptTextCreatorHandler = (filterText: string) => string; type ShouldKeyDownEventCreateNewOptionHandler = (arg: { keyCode: number }) => boolean; - type OnChangeSingleHandler = OnChangeHandler>; - type OnChangeMultipleHandler = OnChangeHandler>; - type OnChangeHandler = (newValue: TOption | null) => void; - type OnNewOptionClickHandler = (option: Option) => void; + type OnChangeSingleHandler = OnChangeHandler>; + type OnChangeMultipleHandler = OnChangeHandler>; + type OnChangeHandler | Options> = (newValue: TOption | null) => void; + type OnNewOptionClickHandler = (option: Option) => void; - type LoadOptionsHandler = LoadOptionsAsyncHandler | LoadOptionsLegacyHandler; - type LoadOptionsAsyncHandler = (input: string) => Promise; - type LoadOptionsLegacyHandler = (input: string, callback: (err: any, result: AutocompleteResult) => void) => void; + type LoadOptionsHandler = LoadOptionsAsyncHandler | LoadOptionsLegacyHandler; + type LoadOptionsAsyncHandler = (input: string) => Promise>; + type LoadOptionsLegacyHandler = (input: string, callback: (err: any, result: AutocompleteResult) => void) => void; - interface AutocompleteResult { + interface AutocompleteResult { /** The search-results to be displayed */ - options: Options; + options: Options; /** * Should be set to true, if and only if a longer query with the same prefix * would return a subset of the results @@ -93,17 +93,17 @@ declare namespace ReactSelectClass { type OptionValues = string | number | boolean; - interface MenuRendererProps { + interface MenuRendererProps { /** * The currently focused option; should be visible in the menu by default. * default {} */ - focusedOption: Option; + focusedOption: Option; /** * Callback to focus a new option; receives the option as a parameter. */ - focusOption: FocusOptionHandler; + focusOption: FocusOptionHandler; /** * Option labels are accessible with this string key. @@ -113,17 +113,17 @@ declare namespace ReactSelectClass { /** * Ordered array of options to render. */ - options: Options; + options: Options; /** * Callback to select a new option; receives the option as a parameter. */ - selectValue: SelectValueHandler; + selectValue: SelectValueHandler; /** * Array of currently selected options. */ - valueArray: Options; + valueArray: Options; } interface ArrowRendererProps { @@ -133,7 +133,7 @@ declare namespace ReactSelectClass { onMouseDown: React.MouseEventHandler; } - interface ReactSelectProps extends React.Props { + interface ReactSelectProps extends React.Props> { /** * text to display when `allowCreate` is true. * @default 'Add "{label}"?' @@ -206,11 +206,11 @@ declare namespace ReactSelectClass { /** * method to filter a single option */ - filterOption?: FilterOptionHandler; + filterOption?: FilterOptionHandler; /** * method to filter the options array */ - filterOptions?: FilterOptionsHandler; + filterOptions?: FilterOptionsHandler; /** * whether to strip diacritics when filtering * @default true @@ -273,7 +273,7 @@ declare namespace ReactSelectClass { /** * renders a custom menu with options */ - menuRenderer?: MenuRendererHandler; + menuRenderer?: MenuRendererHandler; /** * optional style to apply to the menu */ @@ -304,7 +304,7 @@ declare namespace ReactSelectClass { /** * onChange handler: function (newValue) {} */ - onChange?: OnChangeHandler; + onChange?: OnChangeHandler; /** * fires when the menu is closed */ @@ -350,12 +350,12 @@ declare namespace ReactSelectClass { /** * function which returns a custom way to render the options in the menu */ - optionRenderer?: OptionRendererHandler; + optionRenderer?: OptionRendererHandler; /** * array of Select options * @default false */ - options?: Options; + options?: Options; /** * field placeholder, displayed when there's no value * @default "Select..." @@ -387,7 +387,7 @@ declare namespace ReactSelectClass { /** * initial field value */ - value?: Option | Options | string | string[] | number | number[] | boolean; + value?: Option | Options | string | string[] | number | number[] | boolean; /** * the option property to use for the value * @default "value" @@ -397,7 +397,7 @@ declare namespace ReactSelectClass { * function which returns a custom way to render the value selected * @default false */ - valueRenderer?: ValueRendererHandler; + valueRenderer?: ValueRendererHandler; /** * optional style to apply to the control */ @@ -429,12 +429,12 @@ declare namespace ReactSelectClass { simpleValue?: boolean; } - interface ReactCreatableSelectProps extends ReactSelectProps { + interface ReactCreatableSelectProps extends ReactSelectProps { /** * Searches for any matching option within the set of options. This function prevents * duplicate options from being created. */ - isOptionUnique?: IsOptionUniqueHandler; + isOptionUnique?: IsOptionUniqueHandler; /** * Determines if the current input text represents a valid option. @@ -444,7 +444,7 @@ declare namespace ReactSelectClass { /** * factory to create new options */ - newOptionCreator?: NewOptionCreatorHandler; + newOptionCreator?: NewOptionCreatorHandler; /** * Creates prompt/placeholder for option text. @@ -459,10 +459,10 @@ declare namespace ReactSelectClass { /** * new option click handler: function (option) {} */ - onNewOptionClick?: OnNewOptionClickHandler; + onNewOptionClick?: OnNewOptionClickHandler; } - interface ReactAsyncSelectProps extends ReactSelectProps { + interface ReactAsyncSelectProps extends ReactSelectProps { /** * Whether to auto-load the default async options set. */ @@ -491,7 +491,7 @@ declare namespace ReactSelectClass { /** * function to call to load options asynchronously */ - loadOptions: LoadOptionsHandler; + loadOptions: LoadOptionsHandler; /** * replaces the placeholder while options are loading @@ -524,6 +524,6 @@ declare namespace ReactSelectClass { } } -declare class ReactSelectClass extends React.Component { +declare class ReactSelectClass extends React.Component> { focus(): void; }