From 2d54e2124fd5c867b1ff5dedebb176eb07b57c67 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Fri, 27 Jan 2023 16:29:47 +0800 Subject: [PATCH] fix: type error --- components/checkbox/Checkbox.tsx | 2 +- components/modal/Modal.tsx | 9 +++--- components/vc-input/inputProps.ts | 49 ++++++++++++++---------------- components/vc-tree/Tree.tsx | 4 ++- components/vc-tree/TreeNode.tsx | 2 +- components/vc-tree/contextTypes.ts | 2 +- 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/components/checkbox/Checkbox.tsx b/components/checkbox/Checkbox.tsx index 3626a5330..211a0e83f 100644 --- a/components/checkbox/Checkbox.tsx +++ b/components/checkbox/Checkbox.tsx @@ -37,7 +37,7 @@ export default defineComponent({ }); onMounted(() => { warning( - props.checked !== undefined || checkboxGroup || props.value === undefined, + !!(props.checked !== undefined || checkboxGroup || props.value === undefined), 'Checkbox', '`value` is not validate prop, do you mean `checked`?', ); diff --git a/components/modal/Modal.tsx b/components/modal/Modal.tsx index 99e483022..d58459b17 100644 --- a/components/modal/Modal.tsx +++ b/components/modal/Modal.tsx @@ -12,6 +12,7 @@ import { useLocaleReceiver } from '../locale-provider/LocaleReceiver'; import initDefaultProps from '../_util/props-util/initDefaultProps'; import type { Direction } from '../config-provider'; import type { VueNode } from '../_util/type'; +import { objectType } from '../_util/type'; import { canUseDocElement } from '../_util/styleChecker'; import useConfigInject from '../config-provider/hooks/useConfigInject'; import { getTransitionName } from '../_util/transition'; @@ -55,8 +56,8 @@ export const modalProps = () => ({ icon: PropTypes.any, maskClosable: { type: Boolean, default: undefined }, forceRender: { type: Boolean, default: undefined }, - okButtonProps: Object as PropType, - cancelButtonProps: Object as PropType, + okButtonProps: objectType(), + cancelButtonProps: objectType(), destroyOnClose: { type: Boolean, default: undefined }, wrapClassName: String, maskTransitionName: String, @@ -68,8 +69,8 @@ export const modalProps = () => ({ default: undefined, }, zIndex: Number, - bodyStyle: { type: Object as PropType, default: undefined as CSSProperties }, - maskStyle: { type: Object as PropType, default: undefined as CSSProperties }, + bodyStyle: objectType(), + maskStyle: objectType(), mask: { type: Boolean, default: undefined }, keyboard: { type: Boolean, default: undefined }, wrapProps: Object, diff --git a/components/vc-input/inputProps.ts b/components/vc-input/inputProps.ts index 6ccc8be38..1330d15cd 100644 --- a/components/vc-input/inputProps.ts +++ b/components/vc-input/inputProps.ts @@ -1,7 +1,7 @@ import type { ExtractPropTypes, PropType } from 'vue'; import PropTypes from '../_util/vue-types'; import type { SizeType } from '../config-provider'; -import type { LiteralUnion, VueNode } from '../_util/type'; +import type { VueNode } from '../_util/type'; import type { ChangeEventHandler, CompositionEventHandler, @@ -56,31 +56,28 @@ export const inputProps = () => ({ autocomplete: String, type: { type: String as PropType< - LiteralUnion< - | 'button' - | 'checkbox' - | 'color' - | 'date' - | 'datetime-local' - | 'email' - | 'file' - | 'hidden' - | 'image' - | 'month' - | 'number' - | 'password' - | 'radio' - | 'range' - | 'reset' - | 'search' - | 'submit' - | 'tel' - | 'text' - | 'time' - | 'url' - | 'week', - string - > + | 'button' + | 'checkbox' + | 'color' + | 'date' + | 'datetime-local' + | 'email' + | 'file' + | 'hidden' + | 'image' + | 'month' + | 'number' + | 'password' + | 'radio' + | 'range' + | 'reset' + | 'search' + | 'submit' + | 'tel' + | 'text' + | 'time' + | 'url' + | 'week' >, default: 'text', }, diff --git a/components/vc-tree/Tree.tsx b/components/vc-tree/Tree.tsx index ae0bd218e..a46d02b2b 100644 --- a/components/vc-tree/Tree.tsx +++ b/components/vc-tree/Tree.tsx @@ -1141,7 +1141,7 @@ export default defineComponent({ ); // It's better move to hooks but we just simply keep here - let draggableConfig: DraggableConfig; + let draggableConfig: DraggableConfig | false; if (draggable) { if (typeof draggable === 'object') { draggableConfig = draggable; @@ -1152,6 +1152,8 @@ export default defineComponent({ } else { draggableConfig = {}; } + } else { + draggableConfig = false; } return ( { const { draggable, prefixCls } = context.value; - return draggable?.icon ? ( + return draggable && draggable?.icon ? ( {draggable.icon} ) : null; }; diff --git a/components/vc-tree/contextTypes.ts b/components/vc-tree/contextTypes.ts index 4089364b7..3010c7723 100644 --- a/components/vc-tree/contextTypes.ts +++ b/components/vc-tree/contextTypes.ts @@ -40,7 +40,7 @@ export interface TreeContextProps { showIcon: boolean; icon: IconType; switcherIcon: IconType; - draggable: DraggableConfig; + draggable: DraggableConfig | false; draggingNodeKey?: Key; checkable: boolean; customCheckable: () => any;