From ab6c44dd1fc74029ff14bd53923ac433d3f64112 Mon Sep 17 00:00:00 2001 From: Wei Zhu Date: Thu, 22 Nov 2018 17:50:05 +0800 Subject: [PATCH] types: add generic type for Select[value] usage: const handleChange = (value: string) => {} onChange={handleChange} > --- components/select/index.tsx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/components/select/index.tsx b/components/select/index.tsx index 450f4ec529..47481745f9 100755 --- a/components/select/index.tsx +++ b/components/select/index.tsx @@ -44,23 +44,23 @@ export interface LabeledValue { export type SelectValue = string | string[] | number | number[] | LabeledValue | LabeledValue[]; -export interface SelectProps extends AbstractSelectProps { - value?: SelectValue; - defaultValue?: SelectValue; +export interface SelectProps extends AbstractSelectProps { + value?: T; + defaultValue?: T; mode?: 'default' | 'multiple' | 'tags' | 'combobox' | string; optionLabelProp?: string; firstActiveValue?: string | string[]; - onChange?: (value: SelectValue, option: React.ReactElement | React.ReactElement[]) => void; - onSelect?: (value: SelectValue, option: React.ReactElement) => any; - onDeselect?: (value: SelectValue) => any; - onBlur?: (value: SelectValue) => void; + onChange?: (value: T, option: React.ReactElement | React.ReactElement[]) => void; + onSelect?: (value: T, option: React.ReactElement) => any; + onDeselect?: (value: T) => any; + onBlur?: (value: T) => void; onFocus?: () => void; onPopupScroll?: React.UIEventHandler; onInputKeyDown?: (e: React.KeyboardEvent) => void; onMouseEnter?: (e: React.MouseEvent) => any; onMouseLeave?: (e: React.MouseEvent) => any; maxTagCount?: number; - maxTagPlaceholder?: React.ReactNode | ((omittedValues: SelectValue[]) => React.ReactNode); + maxTagPlaceholder?: React.ReactNode | ((omittedValues: T[]) => React.ReactNode); optionFilterProp?: string; labelInValue?: boolean; tokenSeparators?: string[]; @@ -102,7 +102,7 @@ const SelectPropTypes = { // => It is needless to export the declaration of below two inner components. // export { Option, OptGroup }; -export default class Select extends React.Component { +export default class Select extends React.Component, {}> { static Option = Option as React.ClassicComponentClass; static OptGroup = OptGroup as React.ClassicComponentClass; @@ -119,7 +119,7 @@ export default class Select extends React.Component { private rcSelect: any; - constructor(props: SelectProps) { + constructor(props: SelectProps) { super(props); warning(