From cd517d67437be7661830be6766c558e545a731ff Mon Sep 17 00:00:00 2001 From: dopamine Date: Mon, 23 Sep 2024 13:45:35 +0800 Subject: [PATCH] chore(components): [select-v2] remove ts-nocheck comments in select-v2 (#16746) * chore: remove ts-nocheck comments in select-v2 * take the review comments * improve emits type * the keys of emits use camelCase instead of kebab-case * apply suggestions from code review Co-authored-by: btea <2356281422@qq.com> * reduce duplicate ESLint comments * use more succinct syntax to define props * revert emits to kebab-case * fix: type checking failed * chore: illustrate why return early in validateIcon * fix: signature with duplicate parameter names Co-authored-by: qiang --------- Co-authored-by: btea <2356281422@qq.com> Co-authored-by: qiang --- packages/components/select-v2/src/defaults.ts | 31 ++++++- .../components/select-v2/src/group-item.vue | 8 +- .../components/select-v2/src/option-item.vue | 4 +- .../select-v2/src/select-dropdown.tsx | 81 ++++++++++++------ .../components/select-v2/src/select.types.ts | 15 ++++ packages/components/select-v2/src/select.vue | 18 +--- packages/components/select-v2/src/token.ts | 15 ++-- .../select-v2/src/useAllowCreate.ts | 9 +- .../components/select-v2/src/useOption.ts | 7 +- .../components/select-v2/src/useSelect.ts | 85 ++++++++++--------- packages/components/virtual-list/index.ts | 2 + .../virtual-list/src/builders/build-list.ts | 5 +- .../src/components/dynamic-size-list.ts | 1 + .../src/components/fixed-size-list.ts | 1 + .../virtual-list/src/hooks/use-cache.ts | 5 +- packages/utils/vue/typescript.ts | 4 +- typings/env.d.ts | 4 +- 17 files changed, 187 insertions(+), 108 deletions(-) diff --git a/packages/components/select-v2/src/defaults.ts b/packages/components/select-v2/src/defaults.ts index b5f6c3baa2..c8d320031b 100644 --- a/packages/components/select-v2/src/defaults.ts +++ b/packages/components/select-v2/src/defaults.ts @@ -4,7 +4,13 @@ import { useEmptyValuesProps, useSizeProp, } from '@element-plus/hooks' -import { buildProps, definePropType, iconPropType } from '@element-plus/utils' +import { + buildProps, + definePropType, + iconPropType, + isNumber, +} from '@element-plus/utils' +import { CHANGE_EVENT, UPDATE_MODEL_EVENT } from '@element-plus/constants' import { useTooltipContentProps } from '@element-plus/components/tooltip' import { CircleClose } from '@element-plus/icons-vue' import { tagProps } from '../../tag' @@ -12,6 +18,8 @@ import { defaultProps } from './useProps' import type { Option, OptionType } from './select.types' import type { Props } from './useProps' +import type { EmitFn } from '@element-plus/utils/vue/typescript' +import type { ExtractPropTypes } from 'vue' import type { Options, Placement, @@ -269,3 +277,24 @@ export const OptionProps = buildProps({ selected: Boolean, created: Boolean, } as const) + +/* eslint-disable @typescript-eslint/no-unused-vars */ +export const selectEmits = { + [UPDATE_MODEL_EVENT]: (val: ISelectV2Props['modelValue']) => true, + [CHANGE_EVENT]: (val: ISelectV2Props['modelValue']) => true, + 'remove-tag': (val: unknown) => true, + 'visible-change': (visible: boolean) => true, + focus: (evt: FocusEvent) => evt instanceof FocusEvent, + blur: (evt: FocusEvent) => evt instanceof FocusEvent, + clear: () => true, +} +export const optionEmits = { + hover: (index?: number) => isNumber(index), + select: (val: Option, index?: number) => true, +} +/* eslint-enable @typescript-eslint/no-unused-vars */ + +export type ISelectV2Props = ExtractPropTypes +export type IOptionV2Props = ExtractPropTypes +export type SelectEmitFn = EmitFn +export type OptionEmitFn = EmitFn diff --git a/packages/components/select-v2/src/group-item.vue b/packages/components/select-v2/src/group-item.vue index cd1cdb6cdf..594fa64071 100644 --- a/packages/components/select-v2/src/group-item.vue +++ b/packages/components/select-v2/src/group-item.vue @@ -1,16 +1,16 @@