diff --git a/src/Cascader.tsx b/src/Cascader.tsx index f67c9840..a0f588c4 100644 --- a/src/Cascader.tsx +++ b/src/Cascader.tsx @@ -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` +// 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; + children?: DefaultOptionType[] | undefined; } export type DefaultOptionType = BaseOptionType & Record; @@ -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; @@ -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; @@ -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,