fix: cascader's onChange ts adapts to single and multiple (#33947)

* fix to: cascader's multiple determines the declaration of onChange

* fix: cascader's onChange ts adapts to single and multiple

* test: fix
This commit is contained in:
babycannotsay 2022-02-12 21:56:55 +08:00 committed by GitHub
parent 31fb55adf3
commit a7e8f1034f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 3 deletions

View File

@ -74,4 +74,18 @@ describe('Cascader.typescript', () => {
);
expect(wrapper).toBeTruthy();
});
it('single onChange', () => {
const wrapper = mount(
<Cascader multiple={false} onChange={(values: (string | number)[]) => values} />,
);
expect(wrapper).toBeTruthy();
});
it('multiple onChange', () => {
const wrapper = mount(
<Cascader multiple onChange={(values: (string | number)[][]) => values} />,
);
expect(wrapper).toBeTruthy();
});
});

View File

@ -2,7 +2,8 @@ import * as React from 'react';
import classNames from 'classnames';
import RcCascader from 'rc-cascader';
import type {
CascaderProps as RcCascaderProps,
SingleCascaderProps as RcSingleCascaderProps,
MultipleCascaderProps as RcMultipleCascaderProps,
ShowSearchType,
FieldNames,
BaseOptionType,
@ -80,8 +81,16 @@ const defaultSearchRender: ShowSearchType['render'] = (inputValue, path, prefixC
return optionList;
};
export interface CascaderProps<DataNodeType>
extends Omit<RcCascaderProps, 'checkable' | 'options'> {
type SingleCascaderProps = Omit<RcSingleCascaderProps, 'checkable' | 'options'> & {
multiple?: false;
};
type MultipleCascaderProps = Omit<RcMultipleCascaderProps, 'checkable' | 'options'> & {
multiple: true;
};
type UnionCascaderProps = SingleCascaderProps | MultipleCascaderProps;
export type CascaderProps<DataNodeType> = UnionCascaderProps & {
multiple?: boolean;
size?: SizeType;
bordered?: boolean;