Edit:
React-Select v5 now natively supports TypeScript, therefore some type changes have been made (details).
Here's an updated example for v5 (react-select/async), similar to the original one with v4:
import ReactSelectAsync, { AsyncProps } from "react-select/async";
import { GroupBase } from "react-select";
interface CustomSelectAsyncProps {
additionalCustomProp: number;
}
function SelectAsync<
OptionType,
IsMulti extends boolean = false,
GroupType extends GroupBase<OptionType> = GroupBase<OptionType>
>({
additionalCustomProp,
...props
}: AsyncProps<OptionType, IsMulti, GroupType> & CustomSelectAsyncProps) {
return <ReactSelectAsync {...props} />;
}
export default SelectAsync;
Codesandbox
Original Answer:
This is documented on the official react-select documentation.
Quote:
Wrapping the Select component
Oftentimes the Select component is wrapped in another component that is used throughout an app and the wrapper should be just as flexible as the original Select component (i.e., allow for different Option types, groups, single-select, or multi-select). In order to provide this flexibility, the wrapping component should re-declare the generics and forward them to the underlying Select. Here is an example of how to do that:
function CustomSelect<
Option,
IsMulti extends boolean = false,
Group extends GroupBase<Option> = GroupBase<Option>
>(props: Props<Option, IsMulti, Group>) {
return (
<Select {...props} theme={(theme) => ({ ...theme, borderRadius: 0 })} />
);
}
It also explains how to extend the props with additional custom props:
You can use module augmentation to add custom props to the Select prop types:
declare module 'react-select/dist/declarations/src/Select' {
export interface Props<
Option,
IsMulti extends boolean,
Group extends GroupBase<Option>
> {
myCustomProp: string;
}
}
But I personally prefer to just add a custom interface using the & character with a custom interface to add custom props (example with ReactSelectAsync, see ... & CustomSelectAsyncProps):
interface CustomSelectAsyncProps {
additionalCustomProp: number;
}
function SelectAsync<
OptionType extends OptionTypeBase,
IsMulti extends boolean = false,
GroupType extends GroupTypeBase<OptionType> = GroupTypeBase<OptionType>
>({
additionalCustomProp,
...props
}: Props<OptionType, IsMulti, GroupType> & CustomSelectAsyncProps) {
return (
<ReactSelectAsync {...props} />
);
}