diff --git a/src/Select.tsx b/src/Select.tsx index 5f92562af..23d79463b 100644 --- a/src/Select.tsx +++ b/src/Select.tsx @@ -133,50 +133,36 @@ export interface SharedSelectProps - extends SharedSelectProps { +export interface SingleSelectProps< + ValueType = any, + OptionType extends BaseOptionType = DefaultOptionType, +> extends SharedSelectProps { mode?: 'combobox'; - labelInValue?: false; - value?: RawValueType | null; - defaultValue?: RawValueType | null; - onChange?: (value: RawValueType, option: OptionType) => void; + labelInValue?: boolean; + value?: ValueType | null; + defaultValue?: ValueType | null; + onChange?: (value: ValueType, option: OptionType) => void; } -export interface SingleLabeledSelectProps - extends SharedSelectProps { - mode?: 'combobox'; - labelInValue: true; - value?: LabelInValueType | null; - defaultValue?: LabelInValueType | null; - onChange?: (value: LabelInValueType, option: OptionType) => void; -} - -export interface MultipleRawSelectProps - extends SharedSelectProps { +export interface MultipleSelectProps< + ValueType = any[], + OptionType extends BaseOptionType = DefaultOptionType, +> extends SharedSelectProps { mode: 'multiple' | 'tags'; - labelInValue?: false; - value?: RawValueType[] | null; - defaultValue?: RawValueType[] | null; - onChange?: (value: RawValueType[], option: OptionType[]) => void; + labelInValue?: boolean; + value?: ValueType[] | null; + defaultValue?: ValueType[] | null; + onChange?: (value: ValueType[], option: OptionType[]) => void; } -export interface MultipleLabeledSelectProps - extends SharedSelectProps { - mode: 'multiple' | 'tags'; - labelInValue: true; - value?: LabelInValueType[] | null; - defaultValue?: LabelInValueType[] | null; - onChange?: (value: LabelInValueType[], option: OptionType[]) => void; -} +export type SelectProps = + | SingleSelectProps + | MultipleSelectProps; -// TODO: Types test -export type SelectProps = Omit< - | SingleRawSelectProps - | SingleLabeledSelectProps - | MultipleRawSelectProps - | MultipleLabeledSelectProps, - 'onChange' -> & { +export type InternalSelectProps< + ValueType = any, + OptionType extends BaseOptionType = DefaultOptionType, +> = Omit, 'onChange'> & { onChange?: (value: DraftValueType, option: OptionType | OptionType[]) => void; }; @@ -185,7 +171,7 @@ function isRawValue(value: DraftValueType): value is RawValueType { } const Select = React.forwardRef( - (props: SelectProps, ref: React.Ref) => { + (props: InternalSelectProps, ref: React.Ref) => { const { id, mode, @@ -661,9 +647,10 @@ if (process.env.NODE_ENV !== 'production') { } const TypedSelect = Select as unknown as (< - Values extends BaseOptionType | DefaultOptionType = DefaultOptionType, + ValueType = any, + OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType, >( - props: React.PropsWithChildren> & { + props: React.PropsWithChildren> & { ref?: React.Ref; }, ) => React.ReactElement) & { diff --git a/src/utils/warningPropsUtil.ts b/src/utils/warningPropsUtil.ts index efeb09f16..6f3c00c9b 100644 --- a/src/utils/warningPropsUtil.ts +++ b/src/utils/warningPropsUtil.ts @@ -1,13 +1,17 @@ import * as React from 'react'; import warning, { noteOnce } from 'rc-util/lib/warning'; import toNodeArray from 'rc-util/lib/Children/toArray'; -import type { SelectProps } from '..'; import { convertChildrenToData } from './legacyUtil'; import { toArray } from './commonUtil'; -import type { RawValueType, LabelInValueType, BaseOptionType } from '../Select'; +import type { + RawValueType, + LabelInValueType, + BaseOptionType, + InternalSelectProps, +} from '../Select'; import { isMultiple } from '../BaseSelect'; -function warningProps(props: SelectProps) { +function warningProps(props: InternalSelectProps) { const { mode, options,