diff --git a/components/switch/index.tsx b/components/switch/index.tsx index cfd7e2591..0d038946a 100644 --- a/components/switch/index.tsx +++ b/components/switch/index.tsx @@ -11,7 +11,7 @@ import Omit from 'omit.js'; import useConfigInject from '../_util/hooks/useConfigInject'; export const SwitchSizes = tuple('small', 'default'); - +type CheckedType = boolean | string | number; const switchProps = { prefixCls: PropTypes.string, size: PropTypes.oneOf(SwitchSizes), @@ -21,14 +21,20 @@ const switchProps = { tabindex: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), autofocus: PropTypes.looseBool, loading: PropTypes.looseBool, - checked: PropTypes.any, - checkedValue: PropTypes.any.def(true), - unCheckedValue: PropTypes.any.def(false), + checked: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.looseBool]), + checkedValue: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.looseBool]).def( + true, + ), + unCheckedValue: PropTypes.oneOfType([ + PropTypes.string, + PropTypes.number, + PropTypes.looseBool, + ]).def(false), onChange: { - type: Function as PropType<(checked: any, e: Event) => void>, + type: Function as PropType<(checked: CheckedType, e: Event) => void>, }, onClick: { - type: Function as PropType<(checked: any, e: Event) => void>, + type: Function as PropType<(checked: CheckedType, e: Event) => void>, }, onKeydown: { type: Function as PropType<(e: Event) => void>, @@ -37,7 +43,7 @@ const switchProps = { type: Function as PropType<(e: Event) => void>, }, 'onUpdate:checked': { - type: Function as PropType<(checked: any) => void>, + type: Function as PropType<(checked: CheckedType) => void>, }, }; @@ -92,7 +98,7 @@ const Switch = defineComponent({ }); }); - const setChecked = (check: any, e: MouseEvent | KeyboardEvent) => { + const setChecked = (check: CheckedType, e: MouseEvent | KeyboardEvent) => { if (props.disabled) { return; } diff --git a/v2-doc b/v2-doc index 89612874e..b9934e0de 160000 --- a/v2-doc +++ b/v2-doc @@ -1 +1 @@ -Subproject commit 89612874e476dc788711cdaedfd037b9497e5e78 +Subproject commit b9934e0de1052a73978cdb9fb401fa7b5eaf8ecc