fix: typescript compile error (#4624)

pull/4632/head
Amour1688 2021-09-07 14:16:46 +08:00 committed by GitHub
parent 3b08eee8c7
commit 9cd4783fd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 15 deletions

View File

@ -13,7 +13,7 @@ const initDefaultProps = <T>(
: any; : any;
}, },
): T => { ): T => {
const propTypes: T = { ...types } as T; const propTypes: T = { ...types };
Object.keys(defaultProps).forEach(k => { Object.keys(defaultProps).forEach(k => {
const prop = propTypes[k] as VueTypeValidableDef; const prop = propTypes[k] as VueTypeValidableDef;
if (prop) { if (prop) {

View File

@ -38,7 +38,7 @@ import { getSeparatedContent } from './utils/valueUtil';
import useSelectTriggerControl from './hooks/useSelectTriggerControl'; import useSelectTriggerControl from './hooks/useSelectTriggerControl';
import useCacheDisplayValue from './hooks/useCacheDisplayValue'; import useCacheDisplayValue from './hooks/useCacheDisplayValue';
import useCacheOptions from './hooks/useCacheOptions'; import useCacheOptions from './hooks/useCacheOptions';
import type { CSSProperties, DefineComponent, PropType, VNode, VNodeChild } from 'vue'; import type { CSSProperties, PropType, VNode, VNodeChild } from 'vue';
import { import {
computed, computed,
defineComponent, defineComponent,
@ -137,7 +137,7 @@ export const BaseProps = () => ({
maxTagTextLength: PropTypes.number, maxTagTextLength: PropTypes.number,
maxTagCount: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), maxTagCount: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
maxTagPlaceholder: PropTypes.any, maxTagPlaceholder: PropTypes.any,
tokenSeparators: PropTypes.array, tokenSeparators: PropTypes.arrayOf(PropTypes.string),
tagRender: PropTypes.func, tagRender: PropTypes.func,
showAction: PropTypes.array, showAction: PropTypes.array,
tabindex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), tabindex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
@ -285,7 +285,10 @@ export interface SelectProps<OptionsType extends object[], ValueType> {
export interface GenerateConfig<OptionsType extends object[]> { export interface GenerateConfig<OptionsType extends object[]> {
prefixCls: string; prefixCls: string;
components: { components: {
optionList: DefineComponent<Omit<OptionListProps, 'options'> & { options?: OptionsType }>; // TODO
optionList: (
props: Omit<OptionListProps, 'options'> & { options?: OptionsType },
) => JSX.Element;
}; };
/** Convert jsx tree into `OptionsType` */ /** Convert jsx tree into `OptionsType` */
convertChildrenToData: (children: VNodeChild | JSX.Element) => OptionsType; convertChildrenToData: (children: VNodeChild | JSX.Element) => OptionsType;
@ -313,6 +316,7 @@ export interface GenerateConfig<OptionsType extends object[]> {
) => OptionsType; ) => OptionsType;
omitDOMProps?: (props: object) => object; omitDOMProps?: (props: object) => object;
} }
type ValueType = DefaultValueType; type ValueType = DefaultValueType;
/** /**
* This function is in internal usage. * This function is in internal usage.
@ -338,11 +342,12 @@ export default function generateSelector<
warningProps, warningProps,
fillOptionsWithMissingValue, fillOptionsWithMissingValue,
omitDOMProps, omitDOMProps,
} = config as any; } = config;
const Select = defineComponent<SelectProps<OptionsType, ValueType>>({ const Select = defineComponent({
name: 'Select', name: 'Select',
slots: ['option'], slots: ['option'],
setup(props: SelectProps<OptionsType, ValueType>) { props: initDefaultProps(BaseProps(), {}),
setup(props) {
const useInternalProps = computed( const useInternalProps = computed(
() => props.internalProps && props.internalProps.mark === INTERNAL_PROPS_MARK, () => props.internalProps && props.internalProps.mark === INTERNAL_PROPS_MARK,
); );
@ -442,9 +447,9 @@ export default function generateSelector<
}); });
const mergedOptions = computed((): OptionsType => { const mergedOptions = computed((): OptionsType => {
let newOptions = props.options; let newOptions = props.options as OptionsType;
if (newOptions === undefined) { 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` // Check if match the `tokenSeparators`
const patchLabels: string[] = isCompositing const patchLabels: string[] = isCompositing
? null ? null
: getSeparatedContent(searchText, props.tokenSeparators); : getSeparatedContent(searchText, props.tokenSeparators as string[]);
let patchRawValues: RawValueType[] = patchLabels; let patchRawValues: RawValueType[] = patchLabels;
if (props.mode === 'combobox') { if (props.mode === 'combobox') {
@ -913,12 +918,12 @@ export default function generateSelector<
if (props.disabled) { if (props.disabled) {
return; return;
} }
const serachVal = mergedSearchValue.value; const searchVal = mergedSearchValue.value;
if (serachVal) { if (searchVal) {
// `tags` mode should move `searchValue` into values // `tags` mode should move `searchValue` into values
if (props.mode === 'tags') { if (props.mode === 'tags') {
triggerSearch('', false, false); triggerSearch('', false, false);
triggerChange(Array.from(new Set([...mergedRawValue.value, serachVal]))); triggerChange(Array.from(new Set([...mergedRawValue.value, searchVal])));
} else if (props.mode === 'multiple') { } else if (props.mode === 'multiple') {
// `multiple` mode only clean the search value but not trigger event // `multiple` mode only clean the search value but not trigger event
setInnerSearchValue(''); setInnerSearchValue('');
@ -1096,7 +1101,7 @@ export default function generateSelector<
activeValue, activeValue,
onSearchSubmit, onSearchSubmit,
$slots: slots, $slots: slots,
} = this as any; } = this;
const { const {
prefixCls = defaultPrefixCls, prefixCls = defaultPrefixCls,
class: className, class: className,
@ -1356,6 +1361,6 @@ export default function generateSelector<
); );
}, },
}); });
Select.props = initDefaultProps(BaseProps(), {});
return Select; return Select;
} }