From dc93c443f7cb3f8afb3a22b5913cc64c2cd578ee Mon Sep 17 00:00:00 2001 From: Amour1688 Date: Tue, 7 Sep 2021 13:15:07 +0800 Subject: [PATCH] fix: typescript compile error --- .../_util/props-util/initDefaultProps.ts | 2 +- components/vc-select/generate.tsx | 33 +++++++++++-------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/components/_util/props-util/initDefaultProps.ts b/components/_util/props-util/initDefaultProps.ts index 8c01271ceb..86c0e7df98 100644 --- a/components/_util/props-util/initDefaultProps.ts +++ b/components/_util/props-util/initDefaultProps.ts @@ -13,7 +13,7 @@ const initDefaultProps = ( : any; }, ): T => { - const propTypes: T = { ...types } as T; + const propTypes: T = { ...types }; Object.keys(defaultProps).forEach(k => { const prop = propTypes[k] as VueTypeValidableDef; if (prop) { diff --git a/components/vc-select/generate.tsx b/components/vc-select/generate.tsx index ffadc8501d..e1b89e48da 100644 --- a/components/vc-select/generate.tsx +++ b/components/vc-select/generate.tsx @@ -38,7 +38,7 @@ import { getSeparatedContent } from './utils/valueUtil'; import useSelectTriggerControl from './hooks/useSelectTriggerControl'; import useCacheDisplayValue from './hooks/useCacheDisplayValue'; import useCacheOptions from './hooks/useCacheOptions'; -import type { CSSProperties, DefineComponent, PropType, VNode, VNodeChild } from 'vue'; +import type { CSSProperties, PropType, VNode, VNodeChild } from 'vue'; import { computed, defineComponent, @@ -137,7 +137,7 @@ export const BaseProps = () => ({ maxTagTextLength: PropTypes.number, maxTagCount: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), maxTagPlaceholder: PropTypes.any, - tokenSeparators: PropTypes.array, + tokenSeparators: PropTypes.arrayOf(PropTypes.string), tagRender: PropTypes.func, showAction: PropTypes.array, tabindex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), @@ -285,7 +285,10 @@ export interface SelectProps { export interface GenerateConfig { prefixCls: string; components: { - optionList: DefineComponent & { options?: OptionsType }>; + // TODO + optionList: ( + props: Omit & { options?: OptionsType }, + ) => JSX.Element; }; /** Convert jsx tree into `OptionsType` */ convertChildrenToData: (children: VNodeChild | JSX.Element) => OptionsType; @@ -313,6 +316,7 @@ export interface GenerateConfig { ) => OptionsType; omitDOMProps?: (props: object) => object; } + type ValueType = DefaultValueType; /** * This function is in internal usage. @@ -338,11 +342,12 @@ export default function generateSelector< warningProps, fillOptionsWithMissingValue, omitDOMProps, - } = config as any; - const Select = defineComponent>({ + } = config; + const Select = defineComponent({ name: 'Select', slots: ['option'], - setup(props: SelectProps) { + props: initDefaultProps(BaseProps(), {}), + setup(props) { const useInternalProps = computed( () => props.internalProps && props.internalProps.mark === INTERNAL_PROPS_MARK, ); @@ -442,9 +447,9 @@ export default function generateSelector< }); const mergedOptions = computed((): OptionsType => { - let newOptions = props.options; + let newOptions = props.options as OptionsType; if (newOptions === undefined) { - newOptions = convertChildrenToData(props.children); + newOptions = convertChildrenToData(props.children as VNodeChild); } /** @@ -733,7 +738,7 @@ export default function generateSelector< // Check if match the `tokenSeparators` const patchLabels: string[] = isCompositing ? null - : getSeparatedContent(searchText, props.tokenSeparators); + : getSeparatedContent(searchText, props.tokenSeparators as string[]); let patchRawValues: RawValueType[] = patchLabels; if (props.mode === 'combobox') { @@ -913,12 +918,12 @@ export default function generateSelector< if (props.disabled) { return; } - const serachVal = mergedSearchValue.value; - if (serachVal) { + const searchVal = mergedSearchValue.value; + if (searchVal) { // `tags` mode should move `searchValue` into values if (props.mode === 'tags') { triggerSearch('', false, false); - triggerChange(Array.from(new Set([...mergedRawValue.value, serachVal]))); + triggerChange(Array.from(new Set([...mergedRawValue.value, searchVal]))); } else if (props.mode === 'multiple') { // `multiple` mode only clean the search value but not trigger event setInnerSearchValue(''); @@ -1096,7 +1101,7 @@ export default function generateSelector< activeValue, onSearchSubmit, $slots: slots, - } = this as any; + } = this; const { prefixCls = defaultPrefixCls, class: className, @@ -1356,6 +1361,6 @@ export default function generateSelector< ); }, }); - Select.props = initDefaultProps(BaseProps(), {}); + return Select; }