Skip to content

fix: typescript compile error #4624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/_util/props-util/initDefaultProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const initDefaultProps = <T>(
: 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) {
Expand Down
33 changes: 19 additions & 14 deletions components/vc-select/generate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]),
Expand Down Expand Up @@ -285,7 +285,10 @@ export interface SelectProps<OptionsType extends object[], ValueType> {
export interface GenerateConfig<OptionsType extends object[]> {
prefixCls: string;
components: {
optionList: DefineComponent<Omit<OptionListProps, 'options'> & { options?: OptionsType }>;
// TODO
optionList: (
props: Omit<OptionListProps, 'options'> & { options?: OptionsType },
) => JSX.Element;
};
/** Convert jsx tree into `OptionsType` */
convertChildrenToData: (children: VNodeChild | JSX.Element) => OptionsType;
Expand Down Expand Up @@ -313,6 +316,7 @@ export interface GenerateConfig<OptionsType extends object[]> {
) => OptionsType;
omitDOMProps?: (props: object) => object;
}

type ValueType = DefaultValueType;
/**
* This function is in internal usage.
Expand All @@ -338,11 +342,12 @@ export default function generateSelector<
warningProps,
fillOptionsWithMissingValue,
omitDOMProps,
} = config as any;
const Select = defineComponent<SelectProps<OptionsType, ValueType>>({
} = config;
const Select = defineComponent({
name: 'Select',
slots: ['option'],
setup(props: SelectProps<OptionsType, ValueType>) {
props: initDefaultProps(BaseProps(), {}),
setup(props) {
const useInternalProps = computed(
() => props.internalProps && props.internalProps.mark === INTERNAL_PROPS_MARK,
);
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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('');
Expand Down Expand Up @@ -1096,7 +1101,7 @@ export default function generateSelector<
activeValue,
onSearchSubmit,
$slots: slots,
} = this as any;
} = this;
const {
prefixCls = defaultPrefixCls,
class: className,
Expand Down Expand Up @@ -1356,6 +1361,6 @@ export default function generateSelector<
);
},
});
Select.props = initDefaultProps(BaseProps(), {});

return Select;
}