Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions src/Cascader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ import {
import { formatStrategyValues, toPathOptions } from './utils/treeUtil';
import { warningNullOptions } from './utils/warningPropsUtil';

// Members carry `| undefined` to stay identical to how `Required<OptionType>`
// strips them under `exactOptionalPropertyTypes` (#670).
export interface BaseOptionType {
disabled?: boolean;
disableCheckbox?: boolean;
disabled?: boolean | undefined;
disableCheckbox?: boolean | undefined;
label?: React.ReactNode;
value?: string | number | null;
children?: DefaultOptionType[];
value?: string | number | null | undefined;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
children?: DefaultOptionType[] | undefined;
}

export type DefaultOptionType = BaseOptionType & Record<string, any>;
Expand Down Expand Up @@ -72,7 +74,10 @@ interface BaseCascaderProps<
ValueField extends keyof OptionType = keyof OptionType,
> extends Omit<
BaseSelectPropsWithoutPrivate,
'tokenSeparators' | 'labelInValue' | 'mode' | 'showSearch'
// 'placement' is omitted and redeclared below with the indexed access so
// consumers can still pass explicit `undefined` under
// `exactOptionalPropertyTypes` (#671).
'tokenSeparators' | 'labelInValue' | 'mode' | 'showSearch' | 'placement'
> {
// MISC
id?: string;
Expand Down Expand Up @@ -117,6 +122,9 @@ interface BaseCascaderProps<
popupClassName?: string;
popupMenuColumnStyle?: React.CSSProperties;

// Keep the indexed access (it includes `undefined` under
// `exactOptionalPropertyTypes`) so consumers can still pass an explicit
// undefined; 'placement' is omitted from the extends clause above (#671).
placement?: BaseSelectPropsWithoutPrivate['placement'];
builtinPlacements?: BuildInPlacements;

Expand All @@ -139,11 +147,16 @@ export interface FieldNames<
export type ValueType<
OptionType extends DefaultOptionType = DefaultOptionType,
ValueField extends keyof OptionType = keyof OptionType,
> = keyof OptionType extends ValueField
? unknown extends OptionType['value']
? OptionType[ValueField]
: OptionType['value']
: OptionType[ValueField];
> = Exclude<
keyof OptionType extends ValueField
? unknown extends OptionType['value']
? OptionType[ValueField]
: OptionType['value']
: OptionType[ValueField],
// BaseOptionType.value carries `| undefined` (#670); a selected value is
// never undefined while `null` stays part of the callback contract.
undefined
>;

export type GetValueType<
OptionType extends DefaultOptionType = DefaultOptionType,
Expand Down