From 21ee7f99f2d2969d4c0ba7cea93ed8eaa270c5f1 Mon Sep 17 00:00:00 2001 From: zhanglecong <07akioni2@gmail.com> Date: Mon, 18 Dec 2023 10:00:48 +0800 Subject: [PATCH] fix: eslint --- package.json | 6 +- scripts/release-changelog.mjs | 14 --- .../src/FadeInExpandTransition.ts | 1 + src/_internal/scrollbar/src/Scrollbar.tsx | 2 + src/_internal/select-menu/src/SelectMenu.tsx | 8 +- src/_internal/selection/src/Selection.tsx | 8 +- src/_utils/composable/use-collection.ts | 8 +- src/affix/src/Affix.tsx | 10 ++- src/alert/src/Alert.tsx | 1 + src/carousel/src/Carousel.tsx | 5 +- src/cascader/src/Cascader.tsx | 2 +- src/cascader/src/utils.ts | 2 +- src/color-picker/src/ColorInput.tsx | 17 +++- src/color-picker/src/ColorPickerSwatches.tsx | 7 +- src/create.ts | 9 +- src/data-table/src/DataTable.tsx | 1 + src/data-table/src/MainTable.tsx | 1 + src/data-table/src/TableParts/Body.tsx | 10 ++- src/data-table/src/TableParts/Header.tsx | 2 +- src/data-table/tests/DataTable.spec.tsx | 2 +- src/date-picker/src/panel/use-calendar.ts | 8 +- .../src/panel/use-dual-calendar.ts | 12 +-- src/date-picker/src/utils.ts | 6 +- src/date-picker/tests/DatePicker.spec.tsx | 1 + src/drawer/tests/Drawer.spec.tsx | 1 + src/dropdown/src/DropdownGroupHeader.tsx | 8 +- src/dropdown/src/DropdownOption.tsx | 88 +++++++++++-------- src/dropdown/tests/Dropdown.spec.tsx | 1 + src/dynamic-input/src/DynamicInput.tsx | 8 +- src/grid/src/Grid.tsx | 2 +- src/input-number/src/InputNumber.tsx | 4 +- src/layout/src/Layout.tsx | 3 + src/layout/src/LayoutSider.tsx | 3 + src/legacy-grid/src/styles/index.cssr.ts | 4 +- src/legacy-grid/src/styles/rtl.cssr.ts | 4 +- src/legacy-transfer/src/use-transfer-data.ts | 2 +- src/mention/src/Mention.tsx | 1 + src/mention/src/utils.ts | 21 ++--- src/menu/src/use-menu-child.ts | 16 ++-- src/popover/src/Popover.tsx | 1 + src/popover/src/PopoverBody.tsx | 3 +- src/popover/src/interface.ts | 4 +- src/popover/tests/Popover.spec.tsx | 1 + src/popselect/src/Popselect.tsx | 4 +- src/qr-code/src/qrcodegen.ts | 1 + src/scrollbar/src/Scrollbar.tsx | 2 + src/select/src/Select.tsx | 4 +- src/skeleton/src/Skeleton.tsx | 15 +--- src/slider/src/Slider.tsx | 64 +++++++------- src/slider/src/utils.ts | 15 ++-- src/tabs/src/Tab.tsx | 1 + src/tabs/src/Tabs.tsx | 38 +++++--- src/theme-editor/src/ThemeEditor.tsx | 4 +- src/time-picker/tests/TimePicker.spec.ts | 1 + src/tree/src/utils.ts | 8 +- src/upload/src/Upload.tsx | 5 +- 56 files changed, 266 insertions(+), 214 deletions(-) diff --git a/package.json b/package.json index 791342051..5e14d302b 100644 --- a/package.json +++ b/package.json @@ -94,7 +94,7 @@ "@vitejs/plugin-vue": "^4.3.4", "@vue/compiler-sfc": "^3.3.4", "@vue/eslint-config-standard": "^8.0.1", - "@vue/eslint-config-typescript": "^11.0.3", + "@vue/eslint-config-typescript": "^12.0.0", "@vue/server-renderer": "^3.3.4", "@vue/test-utils": "^2.4.1", "autoprefixer": "^10.4.15", @@ -106,7 +106,7 @@ "eslint": "^8.48.0", "eslint-config-prettier": "^9.0.0", "eslint-config-standard": "^17.1.0", - "eslint-config-standard-with-typescript": "^39.0.0", + "eslint-config-standard-with-typescript": "^43.0.0", "eslint-plugin-import": "^2.28.1", "eslint-plugin-markdown": "^3.0.1", "eslint-plugin-n": "^16.0.2", @@ -132,7 +132,7 @@ "rollup-plugin-esbuild": "^6.1.0", "superagent": "^8.1.2", "ts-jest": "^29.1.1", - "typescript": "5.2.2", + "typescript": "5.3.3", "vfonts": "^0.0.3", "vite": "^5.0.4", "vue": "^3.3.4", diff --git a/scripts/release-changelog.mjs b/scripts/release-changelog.mjs index c58e6b5b4..1b407c989 100644 --- a/scripts/release-changelog.mjs +++ b/scripts/release-changelog.mjs @@ -14,23 +14,9 @@ const { DINGTALK_TOKEN_5 } = process.env -if ( - !DINGTALK_TOKEN || - !DINGTALK_TOKEN_2 || - !DINGTALK_TOKEN_3 || - !DINGTALK_TOKEN_4 || - !DINGTALK_TOKEN_5 -) { - console.log('No DINGTALK_TOKEN in your env.') - process.exit(0) -} const { DISCORD_TOKEN } = process.env -if (!DISCORD_TOKEN) { - console.error('No DISCORD_TOKEN in your env.') - process.exit(0) -} async function releaseChangelogToDingTalk() { const allLog = fs diff --git a/src/_internal/fade-in-expand-transition/src/FadeInExpandTransition.ts b/src/_internal/fade-in-expand-transition/src/FadeInExpandTransition.ts index 5fa868c2a..45d45797f 100644 --- a/src/_internal/fade-in-expand-transition/src/FadeInExpandTransition.ts +++ b/src/_internal/fade-in-expand-transition/src/FadeInExpandTransition.ts @@ -100,6 +100,7 @@ export default defineComponent({ if (!group) { ;(resolvedProps as unknown as TransitionProps).mode = mode } + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument return h(type as any, resolvedProps, slots) } } diff --git a/src/_internal/scrollbar/src/Scrollbar.tsx b/src/_internal/scrollbar/src/Scrollbar.tsx index 16b3aba46..1c580958d 100644 --- a/src/_internal/scrollbar/src/Scrollbar.tsx +++ b/src/_internal/scrollbar/src/Scrollbar.tsx @@ -730,6 +730,7 @@ const Scrollbar = defineComponent({ aria-hiddens > {h( + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument (triggerIsNone ? Wrapper : Transition) as any, triggerIsNone ? null : { name: 'fade-in-transition' }, { @@ -823,6 +824,7 @@ const Scrollbar = defineComponent({ aria-hidden > {h( + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument (triggerIsNone ? Wrapper : Transition) as any, triggerIsNone ? null : { name: 'fade-in-transition' }, { diff --git a/src/_internal/select-menu/src/SelectMenu.tsx b/src/_internal/select-menu/src/SelectMenu.tsx index 0dfdcde27..4663eb464 100644 --- a/src/_internal/select-menu/src/SelectMenu.tsx +++ b/src/_internal/select-menu/src/SelectMenu.tsx @@ -302,12 +302,12 @@ export default defineComponent({ } } function handleFocusin (e: FocusEvent): void { - if (selfRef.value?.contains(e.target as any)) { + if (selfRef.value?.contains(e.target as Node | null)) { props.onFocus?.(e) } } function handleFocusout (e: FocusEvent): void { - if (!selfRef.value?.contains(e.relatedTarget as any)) { + if (!selfRef.value?.contains(e.relatedTarget as Node | null)) { props.onBlur?.(e) } } @@ -409,11 +409,11 @@ export default defineComponent({ empty: emptyRef, virtualListContainer () { const { value } = virtualListRef - return value?.listElRef as HTMLElement + return value?.listElRef }, virtualListContent () { const { value } = virtualListRef - return value?.itemsElRef as HTMLElement + return value?.itemsElRef }, doScroll, handleFocusin, diff --git a/src/_internal/selection/src/Selection.tsx b/src/_internal/selection/src/Selection.tsx index 4b1aec866..af22b1809 100644 --- a/src/_internal/selection/src/Selection.tsx +++ b/src/_internal/selection/src/Selection.tsx @@ -739,8 +739,8 @@ export default defineComponent({ }} ) - ) : maxTagCountNumeric ? ( - createOriginalTagNodes().concat(counter as JSX.Element) + ) : maxTagCountNumeric && counter ? ( + createOriginalTagNodes().concat(counter) ) : ( createOriginalTagNodes() ) @@ -889,11 +889,11 @@ export default defineComponent({
{renderTag ? renderTag({ - option: this.selectedOption as SelectBaseOption, + option: this.selectedOption!, handleClose: () => {} }) : renderLabel - ? renderLabel(this.selectedOption as SelectBaseOption, true) + ? renderLabel(this.selectedOption!, true) : render(this.label, this.selectedOption, true)}
diff --git a/src/_utils/composable/use-collection.ts b/src/_utils/composable/use-collection.ts index c0e4d4680..f3c024c6b 100644 --- a/src/_utils/composable/use-collection.ts +++ b/src/_utils/composable/use-collection.ts @@ -15,9 +15,12 @@ import { export function useInjectionInstanceCollection ( injectionName: string | InjectionKey, collectionKey: string, - registerKeyRef: Ref + registerKeyRef: Ref ): void { - const injection = inject(injectionName, null) + const injection = inject> | null>( + injectionName, + null + ) if (injection === null) return const vm = getCurrentInstance()?.proxy watch(registerKeyRef, registerInstance) @@ -26,6 +29,7 @@ export function useInjectionInstanceCollection ( registerInstance(undefined, registerKeyRef.value) }) function registerInstance (key?: string, oldKey?: string): void { + if (!injection) return const collection = injection[collectionKey] if (oldKey !== undefined) removeInstance(collection, oldKey) if (key !== undefined) addInstance(collection, key) diff --git a/src/affix/src/Affix.tsx b/src/affix/src/Affix.tsx index 1b80e1c3a..8cc1e61ac 100644 --- a/src/affix/src/Affix.tsx +++ b/src/affix/src/Affix.tsx @@ -124,11 +124,17 @@ export default defineComponent({ if (!scrollTarget || !selfEl) return const scrollTop = getScrollTop(scrollTarget) if (affixedRef.value) { - if (scrollTop < (topAffixedTriggerScrollTopRef.value as number)) { + if ( + topAffixedTriggerScrollTopRef.value !== null && + scrollTop < topAffixedTriggerScrollTopRef.value + ) { stickToTopRef.value = false topAffixedTriggerScrollTopRef.value = null } - if (scrollTop > (bottomAffixedTriggerScrollTopRef.value as number)) { + if ( + bottomAffixedTriggerScrollTopRef.value !== null && + scrollTop > bottomAffixedTriggerScrollTopRef.value + ) { stickToBottomRef.value = false bottomAffixedTriggerScrollTopRef.value = null } diff --git a/src/alert/src/Alert.tsx b/src/alert/src/Alert.tsx index d60ce237b..756faddd8 100644 --- a/src/alert/src/Alert.tsx +++ b/src/alert/src/Alert.tsx @@ -203,6 +203,7 @@ export default defineComponent({ role: 'alert' } return this.visible ? ( + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
{this.closable && ( +Pick > export const carouselProps = { @@ -574,7 +575,7 @@ export default defineComponent({ dragStartX = touchEvent.clientX } if (props.touchable) { - on('touchmove', document, handleTouchmove, { passive: true } as any) + on('touchmove', document, handleTouchmove) on('touchend', document, handleTouchend) on('touchcancel', document, handleTouchend) } diff --git a/src/cascader/src/Cascader.tsx b/src/cascader/src/Cascader.tsx index 293696a75..ecc0bd0e1 100644 --- a/src/cascader/src/Cascader.tsx +++ b/src/cascader/src/Cascader.tsx @@ -376,7 +376,7 @@ export default defineComponent({ const tmNode = getNode(key) if (tmNode !== null) { cascaderMenuInstRef.value.showErrorMessage( - (tmNode.rawNode as any)[props.labelField] + (tmNode.rawNode as any)[props.labelField] as string ) } } diff --git a/src/cascader/src/utils.ts b/src/cascader/src/utils.ts index 309df3dee..f3a0146a7 100644 --- a/src/cascader/src/utils.ts +++ b/src/cascader/src/utils.ts @@ -54,7 +54,7 @@ function getPathLabel ( ): string { const path: string[] = [] while (node) { - path.push((node.rawNode as any)[labelField]) + path.push((node.rawNode as any)[labelField] as string) node = node.parent } return path.reverse().join(separator) diff --git a/src/color-picker/src/ColorInput.tsx b/src/color-picker/src/ColorInput.tsx index 5fe033a57..9278f70f7 100644 --- a/src/color-picker/src/ColorInput.tsx +++ b/src/color-picker/src/ColorInput.tsx @@ -9,7 +9,10 @@ import { toHexString, toHsvString, toRgbString, - toHslString + toHslString, + type HSV, + type RGB, + type HSL } from 'seemly' import { h, defineComponent, type PropType } from 'vue' import { NInputGroup } from '../../input' @@ -73,19 +76,25 @@ export default defineComponent({ case 'hsv': nextValueArr[index] = value props.onUpdateValue( - (showAlpha ? toHsvaString : toHsvString)(nextValueArr) + (showAlpha ? toHsvaString : toHsvString)( + nextValueArr as HSVA | HSV + ) ) break case 'rgb': nextValueArr[index] = value props.onUpdateValue( - (showAlpha ? toRgbaString : toRgbString)(nextValueArr) + (showAlpha ? toRgbaString : toRgbString)( + nextValueArr as RGBA | RGB + ) ) break case 'hsl': nextValueArr[index] = value props.onUpdateValue( - (showAlpha ? toHslaString : toHslString)(nextValueArr) + (showAlpha ? toHslaString : toHslString)( + nextValueArr as HSLA | HSL + ) ) break } diff --git a/src/color-picker/src/ColorPickerSwatches.tsx b/src/color-picker/src/ColorPickerSwatches.tsx index 6264b5b7f..6d6792f1a 100644 --- a/src/color-picker/src/ColorPickerSwatches.tsx +++ b/src/color-picker/src/ColorPickerSwatches.tsx @@ -16,9 +16,10 @@ function normalizeColor (color: string, mode: ColorPickerMode | null): string { } function getHexFromName (color: string): string { - const ctx = document - .createElement('canvas') - .getContext('2d') as CanvasRenderingContext2D + const ctx = document.createElement('canvas').getContext('2d') + if (!ctx) { + return '#000000' + } ctx.fillStyle = color return ctx.fillStyle } diff --git a/src/create.ts b/src/create.ts index 3e9b1c630..e8d4b0c63 100644 --- a/src/create.ts +++ b/src/create.ts @@ -1,4 +1,4 @@ -import { type App } from 'vue' +import { type Component, type App, type DefineComponent } from 'vue' import version from './version' type ComponentType = any @@ -26,7 +26,10 @@ function create ({ ): void { const registered = app.component(componentPrefix + name) if (!registered) { - app.component(componentPrefix + name, component) + app.component( + componentPrefix + name, + component as Component | DefineComponent + ) } } function install (app: App): void { @@ -34,7 +37,7 @@ function create ({ installTargets.push(app) components.forEach((component) => { const { name, alias } = component - registerComponent(app, name, component) + registerComponent(app, name as string, component) if (alias) { alias.forEach((aliasName: string) => { registerComponent(app, aliasName, component) diff --git a/src/data-table/src/DataTable.tsx b/src/data-table/src/DataTable.tsx index e9c70675d..e4a95ba2c 100644 --- a/src/data-table/src/DataTable.tsx +++ b/src/data-table/src/DataTable.tsx @@ -264,6 +264,7 @@ export default defineComponent({ sort, clearFilter, scrollTo: (arg0: any, arg1?: any) => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument mainTableInstRef.value?.scrollTo(arg0, arg1) } } diff --git a/src/data-table/src/MainTable.tsx b/src/data-table/src/MainTable.tsx index 4fc4961ba..38f497263 100644 --- a/src/data-table/src/MainTable.tsx +++ b/src/data-table/src/MainTable.tsx @@ -63,6 +63,7 @@ export default defineComponent({ getBodyElement, getHeaderElement, scrollTo (arg0: any, arg1?: any) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument bodyInstRef.value?.scrollTo(arg0, arg1) } } diff --git a/src/data-table/src/TableParts/Body.tsx b/src/data-table/src/TableParts/Body.tsx index cac60624c..f38bda266 100644 --- a/src/data-table/src/TableParts/Body.tsx +++ b/src/data-table/src/TableParts/Body.tsx @@ -320,13 +320,13 @@ export default defineComponent({ function handleMouseleaveTable (): void { hoverKeyRef.value = null } - function virtualListContainer (): HTMLElement { + function virtualListContainer (): HTMLElement | null { const { value } = virtualListRef - return value?.listElRef as HTMLElement + return value?.listElRef || null } - function virtualListContent (): HTMLElement { + function virtualListContent (): HTMLElement | null { const { value } = virtualListRef - return value?.itemsElRef as HTMLElement + return value?.itemsElRef || null } function handleVirtualListScroll (e: Event): void { handleTableBodyScroll(e) @@ -341,8 +341,10 @@ export default defineComponent({ getScrollContainer, scrollTo (arg0: any, arg1?: any) { if (virtualScrollRef.value) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument virtualListRef.value?.scrollTo(arg0, arg1) } else { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument scrollbarInstRef.value?.scrollTo(arg0, arg1) } } diff --git a/src/data-table/src/TableParts/Header.tsx b/src/data-table/src/TableParts/Header.tsx index b5c51554d..fe8cec21c 100644 --- a/src/data-table/src/TableParts/Header.tsx +++ b/src/data-table/src/TableParts/Header.tsx @@ -36,7 +36,7 @@ function renderTitle ( column: TableExpandColumn | TableBaseColumn | TableColumnGroup ): VNodeChild { return typeof column.title === 'function' - ? column.title(column as any) + ? column.title(column as never) : column.title } diff --git a/src/data-table/tests/DataTable.spec.tsx b/src/data-table/tests/DataTable.spec.tsx index 0aef91b3b..df524b8d3 100644 --- a/src/data-table/tests/DataTable.spec.tsx +++ b/src/data-table/tests/DataTable.spec.tsx @@ -310,7 +310,7 @@ describe('n-data-table', () => { } ], filter (value: any, row) { - return row.address.includes(value) + return row.address.includes(value as string) } } ] diff --git a/src/date-picker/src/panel/use-calendar.ts b/src/date-picker/src/panel/use-calendar.ts index 8d942af97..d260f6fae 100644 --- a/src/date-picker/src/panel/use-calendar.ts +++ b/src/date-picker/src/panel/use-calendar.ts @@ -378,14 +378,14 @@ function useCalendar ( calendarValueRef.value = getTime(addMonths(calendarValueRef.value, -1)) } // For month type - function virtualListContainer (): HTMLElement { + function virtualListContainer (): HTMLElement | null { const { value } = yearVlRef - return value?.listElRef as HTMLElement + return value?.listElRef || null } // For month type - function virtualListContent (): HTMLElement { + function virtualListContent (): HTMLElement | null { const { value } = yearVlRef - return value?.itemsElRef as HTMLElement + return value?.itemsElRef || null } // For month type function handleVirtualListScroll (e: Event): void { diff --git a/src/date-picker/src/panel/use-dual-calendar.ts b/src/date-picker/src/panel/use-dual-calendar.ts index 7acc5d15b..08ea178c6 100644 --- a/src/date-picker/src/panel/use-dual-calendar.ts +++ b/src/date-picker/src/panel/use-dual-calendar.ts @@ -788,18 +788,18 @@ function useDualCalendar ( function handleEndYearVlScroll (): void { endYearScrollbarRef.value?.sync() } - function virtualListContainer (type: 'start' | 'end'): HTMLElement { + function virtualListContainer (type: 'start' | 'end'): HTMLElement | null { if (type === 'start') { - return startYearVlRef.value?.listElRef as HTMLElement + return startYearVlRef.value?.listElRef || null } else { - return endYearVlRef.value?.listElRef as HTMLElement + return endYearVlRef.value?.listElRef || null } } - function virtualListContent (type: 'start' | 'end'): HTMLElement { + function virtualListContent (type: 'start' | 'end'): HTMLElement | null { if (type === 'start') { - return startYearVlRef.value?.itemsElRef as HTMLElement + return startYearVlRef.value?.itemsElRef || null } else { - return endYearVlRef.value?.itemsElRef as HTMLElement + return endYearVlRef.value?.itemsElRef || null } } const childComponentRefs: RangePanelChildComponentRefs = { diff --git a/src/date-picker/src/utils.ts b/src/date-picker/src/utils.ts index 25842c197..7b71ca7b6 100644 --- a/src/date-picker/src/utils.ts +++ b/src/date-picker/src/utils.ts @@ -55,11 +55,7 @@ function matchDate ( type: 'date' | 'month' | 'year' | 'quarter' ): boolean { const matcher = matcherMap[type] - if (Array.isArray(sourceTime)) { - return sourceTime.some((time) => matcher(time, patternTime)) - } else { - return matcher(sourceTime, patternTime) - } + return matcher(sourceTime, patternTime) } export interface DateItem { diff --git a/src/date-picker/tests/DatePicker.spec.tsx b/src/date-picker/tests/DatePicker.spec.tsx index e69d8ce29..fcb190794 100644 --- a/src/date-picker/tests/DatePicker.spec.tsx +++ b/src/date-picker/tests/DatePicker.spec.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/non-nullable-type-assertion-style */ import { ref } from 'vue' import { mount } from '@vue/test-utils' import { format } from 'date-fns/esm' diff --git a/src/drawer/tests/Drawer.spec.tsx b/src/drawer/tests/Drawer.spec.tsx index 40db982ac..c43ebd13e 100644 --- a/src/drawer/tests/Drawer.spec.tsx +++ b/src/drawer/tests/Drawer.spec.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/non-nullable-type-assertion-style */ import { mount } from '@vue/test-utils' import { defineComponent, h, nextTick, ref } from 'vue' import { NButton } from '../../button' diff --git a/src/dropdown/src/DropdownGroupHeader.tsx b/src/dropdown/src/DropdownGroupHeader.tsx index 09059753d..241a9a2cb 100644 --- a/src/dropdown/src/DropdownGroupHeader.tsx +++ b/src/dropdown/src/DropdownGroupHeader.tsx @@ -1,6 +1,7 @@ import { defineComponent, h, inject } from 'vue' import { render } from '../../_utils' import { dropdownInjectionKey, dropdownMenuInjectionKey } from './context' +import type { DropdownMixedOption } from './interface' export default defineComponent({ name: 'DropdownGroupHeader', @@ -45,7 +46,10 @@ export default defineComponent({ } = this const { rawNode } = this.tmNode const node = ( -
+
@@ -63,7 +67,7 @@ export default defineComponent({ data-dropdown-option > {renderLabel - ? renderLabel(rawNode) + ? renderLabel(rawNode as DropdownMixedOption) : render(rawNode.title ?? rawNode[this.labelField])}
@@ -238,8 +242,7 @@ export default defineComponent({ if (mergedShowSubmenu) { const submenuNodeProps = this.menuProps?.( rawNode, - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - rawNode.children as any + rawNode.children as Array ) submenuVNode = ( - {h('div', mergeProps(builtinProps as any, props as any), [ -
- {[renderIcon ? renderIcon(rawNode) : render(rawNode.icon)]} -
, -
- {/* TODO: Workaround, menu compatible */} - {renderLabel - ? renderLabel(rawNode) - : render(rawNode[this.labelField] ?? rawNode.title)} -
, -
- {this.hasSubmenu ? ( - - {{ - default: () => - }} - - ) : null} -
- ])} + {h( + 'div', + mergeProps( + builtinProps as Record, + props as Record + ), + [ +
+ {[renderIcon ? renderIcon(rawNode) : render(rawNode.icon)]} +
, +
+ {/* TODO: Workaround, menu compatible */} + {renderLabel + ? renderLabel(rawNode) + : render(rawNode[this.labelField] ?? rawNode.title)} +
, +
+ {this.hasSubmenu ? ( + + {{ + default: () => + }} + + ) : null} +
+ ] + )} {this.hasSubmenu ? ( {{ diff --git a/src/dropdown/tests/Dropdown.spec.tsx b/src/dropdown/tests/Dropdown.spec.tsx index 7cdf4d377..f4f4569d3 100644 --- a/src/dropdown/tests/Dropdown.spec.tsx +++ b/src/dropdown/tests/Dropdown.spec.tsx @@ -222,6 +222,7 @@ describe('n-dropdown', () => { expect(triggerNodeWrapper.exists()).toBe(true) await triggerNodeWrapper.trigger('click') + // eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style const disabledMenu = document.querySelector( '.n-dropdown-option-body--disabled' ) as HTMLDivElement diff --git a/src/dynamic-input/src/DynamicInput.tsx b/src/dynamic-input/src/DynamicInput.tsx index 63c9386f2..a56f4e33b 100644 --- a/src/dynamic-input/src/DynamicInput.tsx +++ b/src/dynamic-input/src/DynamicInput.tsx @@ -156,9 +156,9 @@ export default defineComponent({ if (value === undefined || value === null) return index if (typeof value !== 'object') return index const rawValue = isProxy(value) ? toRaw(value) : value - let key = globalDataKeyMap.get(rawValue) + let key = globalDataKeyMap.get(rawValue as WeakKey) if (key === undefined) { - globalDataKeyMap.set(rawValue, (key = createId())) + globalDataKeyMap.set(rawValue as WeakKey, (key = createId())) } return key } @@ -179,9 +179,9 @@ export default defineComponent({ : originalItem const rawNew = isProxy(value) ? toRaw(value) : value // inherit key is value position is not change - const originalKey = globalDataKeyMap.get(rawOriginal) + const originalKey = globalDataKeyMap.get(rawOriginal as WeakKey) if (originalKey !== undefined) { - globalDataKeyMap.set(rawNew, originalKey) + globalDataKeyMap.set(rawNew as WeakKey, originalKey) } } doUpdateValue(newValue) diff --git a/src/grid/src/Grid.tsx b/src/grid/src/Grid.tsx index 51df019f1..80ff5e210 100644 --- a/src/grid/src/Grid.tsx +++ b/src/grid/src/Grid.tsx @@ -252,7 +252,7 @@ export default defineComponent({ if (suffixPropValue !== undefined && suffixPropValue !== false) { suffixSpan = Number( parseResponsivePropValue( - maybeSuffixNode.props?.span, + maybeSuffixNode.props?.span as string | number | null | undefined, responsiveQuery ) ?? defaultSpan ) diff --git a/src/input-number/src/InputNumber.tsx b/src/input-number/src/InputNumber.tsx index 9cd8450ea..1e70ce9d9 100644 --- a/src/input-number/src/InputNumber.tsx +++ b/src/input-number/src/InputNumber.tsx @@ -373,7 +373,7 @@ export default defineComponent({ const { value: mergedValue } = mergedValueRef if (mergedValue === null) { if (!props.validator) { - doUpdateValue(createValidValue() as number) + doUpdateValue(createValidValue()) } } else { const { value: mergedStep } = mergedStepRef @@ -394,7 +394,7 @@ export default defineComponent({ const { value: mergedValue } = mergedValueRef if (mergedValue === null) { if (!props.validator) { - doUpdateValue(createValidValue() as number) + doUpdateValue(createValidValue()) } } else { const { value: mergedStep } = mergedStepRef diff --git a/src/layout/src/Layout.tsx b/src/layout/src/Layout.tsx index 0b89d75b2..051de5c33 100644 --- a/src/layout/src/Layout.tsx +++ b/src/layout/src/Layout.tsx @@ -73,14 +73,17 @@ export function createLayoutComponent (isContent: boolean) { const { value: scrollableEl } = scrollableElRef if (scrollableEl) { if (y === undefined) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument scrollableEl.scrollTo(options as any) } else { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument scrollableEl.scrollTo(options as any, y as any) } } } else { const { value: scrollbarInst } = scrollbarInstRef if (scrollbarInst) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument scrollbarInst.scrollTo(options as any, y as any) } } diff --git a/src/layout/src/LayoutSider.tsx b/src/layout/src/LayoutSider.tsx index 040a5c92c..e451c976f 100644 --- a/src/layout/src/LayoutSider.tsx +++ b/src/layout/src/LayoutSider.tsx @@ -140,14 +140,17 @@ export default defineComponent({ const { value: scrollableEl } = scrollableElRef if (scrollableEl) { if (y === undefined) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument scrollableEl.scrollTo(options as any) } else { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument scrollableEl.scrollTo(options as any, y as any) } } } else { const { value: scrollbarInst } = scrollbarInstRef if (scrollbarInst) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument scrollbarInst.scrollTo(options as any, y as any) } } diff --git a/src/legacy-grid/src/styles/index.cssr.ts b/src/legacy-grid/src/styles/index.cssr.ts index ae15aaa70..00774d370 100644 --- a/src/legacy-grid/src/styles/index.cssr.ts +++ b/src/legacy-grid/src/styles/index.cssr.ts @@ -1,7 +1,7 @@ +import { repeat } from 'seemly' import { c, cB, cM, cE } from '../../../_utils/cssr' -const positionStyles = Array - .apply(null, { length: 24 } as any) +const positionStyles = repeat(24, null) .map((_, index) => { const prefixIndex = index + 1 const percent = `calc(100% / 24 * ${prefixIndex})` diff --git a/src/legacy-grid/src/styles/rtl.cssr.ts b/src/legacy-grid/src/styles/rtl.cssr.ts index 8abeae4b7..91cd1dd30 100644 --- a/src/legacy-grid/src/styles/rtl.cssr.ts +++ b/src/legacy-grid/src/styles/rtl.cssr.ts @@ -1,7 +1,7 @@ +import { repeat } from 'seemly' import { cB, cM } from '../../../_utils/cssr' -const positionStyles = Array - .apply(null, { length: 24 } as any) +const positionStyles = repeat(24, null) .map((_, index) => { const prefixIndex = index + 1 const percent = `calc(100% / 24 * ${prefixIndex})` diff --git a/src/legacy-transfer/src/use-transfer-data.ts b/src/legacy-transfer/src/use-transfer-data.ts index f64ec1f8b..ecff451fe 100644 --- a/src/legacy-transfer/src/use-transfer-data.ts +++ b/src/legacy-transfer/src/use-transfer-data.ts @@ -47,7 +47,7 @@ export function useTransferData ( if (!props.filterable) return tgtOptsRef.value const { filter } = props return tgtOptsRef.value.filter((opt) => - filter(tgtPatternRef.value, opt, 'target') + filter(tgtPatternRef.value, opt as Option, 'target') ) }) const avlSrcValueSetRef = computed( diff --git a/src/mention/src/Mention.tsx b/src/mention/src/Mention.tsx index e0f4c9849..d343dde72 100644 --- a/src/mention/src/Mention.tsx +++ b/src/mention/src/Mention.tsx @@ -169,6 +169,7 @@ export default defineComponent({ // SelectOption { value: string | number, render?: (value: string | number) => VNodeChild } // The 2 types are not compatible since `render`s are not compatible // However we know it works... + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument >(filteredOptionsRef.value as any, { getKey: (v) => { return (v as any).value diff --git a/src/mention/src/utils.ts b/src/mention/src/utils.ts index c00a701b6..911807790 100644 --- a/src/mention/src/utils.ts +++ b/src/mention/src/utils.ts @@ -162,13 +162,14 @@ export function getRelativePosition ( if (isInput && prop === 'lineHeight') { // Special case for s because text is rendered centered and line height may be != height if (computed.boxSizing === 'border-box') { - const height = parseInt(computed.height) + const height = parseInt(computed.height as string) const outerHeight = - parseInt(computed.paddingTop) + - parseInt(computed.paddingBottom) + - parseInt(computed.borderTopWidth) + - parseInt(computed.borderBottomWidth) - const targetHeight = outerHeight + parseInt(computed.lineHeight) + parseInt(computed.paddingTop as string) + + parseInt(computed.paddingBottom as string) + + parseInt(computed.borderTopWidth as string) + + parseInt(computed.borderBottomWidth as string) + const targetHeight = + outerHeight + parseInt(computed.lineHeight as string) if (height > targetHeight) { style.lineHeight = `${height - outerHeight}px` } else if (height === targetHeight) { @@ -186,7 +187,7 @@ export function getRelativePosition ( if (isFirefox) { // Firefox lies about the overflow property for textareas: https://bugzilla.mozilla.org/show_bug.cgi?id=984275 - if (element.scrollHeight > parseInt(computed.height)) { + if (element.scrollHeight > parseInt(computed.height as string)) { style.overflowY = 'scroll' } } else { @@ -213,12 +214,12 @@ export function getRelativePosition ( div.appendChild(span) const relativePosition = { - top: span.offsetTop + parseInt(computed.borderTopWidth), - left: span.offsetLeft + parseInt(computed.borderLeftWidth), + top: span.offsetTop + parseInt(computed.borderTopWidth as string), + left: span.offsetLeft + parseInt(computed.borderLeftWidth as string), absolute: false, // We don't use line-height since it may be too large for position. Eg. 34px // for input - height: parseInt(computed.fontSize) * 1.5 + height: parseInt(computed.fontSize as string) * 1.5 } if (debug) { diff --git a/src/menu/src/use-menu-child.ts b/src/menu/src/use-menu-child.ts index daa6f375b..ea9c73306 100644 --- a/src/menu/src/use-menu-child.ts +++ b/src/menu/src/use-menu-child.ts @@ -90,16 +90,16 @@ export function useMenuChild (props: UseMenuChildProps): UseMenuChild { } return mergedRootIndent } - if (NMenuOptionGroup) { - return indent / 2 + (NMenuOptionGroup.paddingLeftRef.value as number) + if ( + NMenuOptionGroup && + typeof NMenuOptionGroup.paddingLeftRef.value === 'number' + ) { + return indent / 2 + NMenuOptionGroup.paddingLeftRef.value } - if (NSubmenu) { - return ( - (isGroup ? indent / 2 : indent) + - (NSubmenu.paddingLeftRef.value as number) - ) + if (NSubmenu && typeof NSubmenu.paddingLeftRef.value === 'number') { + return (isGroup ? indent / 2 : indent) + NSubmenu.paddingLeftRef.value } - return undefined as never + return 0 }) const iconMarginRightRef = computed(() => { const { collapsedWidth, indent, rootIndent } = menuProps diff --git a/src/popover/src/Popover.tsx b/src/popover/src/Popover.tsx index 6a90b8a24..538924ceb 100644 --- a/src/popover/src/Popover.tsx +++ b/src/popover/src/Popover.tsx @@ -420,6 +420,7 @@ export default defineComponent({ uncontrolledShowRef.value = value } function getTriggerElement (): HTMLElement { + // eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style return binderInstRef.value?.targetRef as HTMLElement } function setBodyInstance (value: BodyInstance | null): void { diff --git a/src/popover/src/PopoverBody.tsx b/src/popover/src/PopoverBody.tsx index 107f5a40e..a4b5200c9 100644 --- a/src/popover/src/PopoverBody.tsx +++ b/src/popover/src/PopoverBody.tsx @@ -132,6 +132,7 @@ export default defineComponent({ mergedClsPrefixRef ) const followerRef = ref(null) + // eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style const NPopover = inject('NPopover') as PopoverInjection const bodyRef = ref(null) const followerEnabledRef = ref(props.show) @@ -444,7 +445,7 @@ export default defineComponent({ `${mergedClsPrefix}-popover-shared--center-arrow` ], bodyRef, - styleRef.value as any, + styleRef, handleMouseEnter, handleMouseLeave ) diff --git a/src/popover/src/interface.ts b/src/popover/src/interface.ts index 078a72c8d..99cccc119 100644 --- a/src/popover/src/interface.ts +++ b/src/popover/src/interface.ts @@ -1,4 +1,4 @@ -import { type Ref, type CSSProperties, type VNode } from 'vue' +import { type Ref, type CSSProperties, type VNode, type ComputedRef } from 'vue' import { createInjectionKey } from '../../_utils/vue/create-injection-key' export type PopoverTrigger = 'click' | 'hover' | 'focus' | 'manual' @@ -20,7 +20,7 @@ export const popoverBodyInjectionKey = export type InternalRenderBody = ( className: any, ref: Ref, - style: Ref, + style: ComputedRef, onMouseenter: (e: MouseEvent) => void, onMouseleave: (e: MouseEvent) => void ) => VNode diff --git a/src/popover/tests/Popover.spec.tsx b/src/popover/tests/Popover.spec.tsx index fa66b3159..97f4f98ef 100644 --- a/src/popover/tests/Popover.spec.tsx +++ b/src/popover/tests/Popover.spec.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unsafe-argument */ import { defineComponent, h, Fragment, nextTick } from 'vue' import { mount } from '@vue/test-utils' import { NPopover, type PopoverInst } from '../index' diff --git a/src/popselect/src/Popselect.tsx b/src/popselect/src/Popselect.tsx index a7efbee2d..50b7f9ac7 100644 --- a/src/popselect/src/Popselect.tsx +++ b/src/popselect/src/Popselect.tsx @@ -100,11 +100,11 @@ export default defineComponent({ ref={createRefSetter(ref)} onMouseenter={mergeEventHandlers([ onMouseenter, - $attrs.onMouseenter as any + $attrs.onMouseenter as ((e: MouseEvent) => void) | undefined ])} onMouseleave={mergeEventHandlers([ onMouseleave, - $attrs.onMouseleave as any + $attrs.onMouseleave as ((e: MouseEvent) => void) | undefined ])} > {{ diff --git a/src/qr-code/src/qrcodegen.ts b/src/qr-code/src/qrcodegen.ts index 6224a1009..d702ef7e1 100644 --- a/src/qr-code/src/qrcodegen.ts +++ b/src/qr-code/src/qrcodegen.ts @@ -699,6 +699,7 @@ namespace qrcodegen { const result: byte[] = divisor.map((_) => 0) for (const b of data) { // Polynomial division + // eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style const factor: byte = b ^ (result.shift() as byte) result.push(0) divisor.forEach( diff --git a/src/scrollbar/src/Scrollbar.tsx b/src/scrollbar/src/Scrollbar.tsx index 4eed5250c..3da5158d7 100644 --- a/src/scrollbar/src/Scrollbar.tsx +++ b/src/scrollbar/src/Scrollbar.tsx @@ -36,9 +36,11 @@ const Scrollbar = defineComponent({ const scrollbarInstRef = ref(null) const exposedMethods: ScrollbarInst = { scrollTo: (...args: any[]) => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument scrollbarInstRef.value?.scrollTo(args[0], args[1]) }, scrollBy: (...args: any[]) => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument scrollbarInstRef.value?.scrollBy(args[0], args[1]) } } diff --git a/src/select/src/Select.tsx b/src/select/src/Select.tsx index 190e24457..52e4f1414 100644 --- a/src/select/src/Select.tsx +++ b/src/select/src/Select.tsx @@ -516,7 +516,7 @@ export default defineComponent({ } } function handleTriggerBlur (e: FocusEvent): void { - if (menuRef.value?.selfRef?.contains(e.relatedTarget as any)) { + if (menuRef.value?.selfRef?.contains(e.relatedTarget as Node | null)) { return } focusedRef.value = false @@ -532,7 +532,7 @@ export default defineComponent({ focusedRef.value = true } function handleMenuBlur (e: FocusEvent): void { - if (triggerRef.value?.$el.contains(e.relatedTarget as any)) return + if (triggerRef.value?.$el.contains(e.relatedTarget as Node | null)) return focusedRef.value = false doBlur(e) // outside select, don't need to return focus diff --git a/src/skeleton/src/Skeleton.tsx b/src/skeleton/src/Skeleton.tsx index 39dfc42e2..2d15e74bd 100644 --- a/src/skeleton/src/Skeleton.tsx +++ b/src/skeleton/src/Skeleton.tsx @@ -1,4 +1,4 @@ -import { pxfy } from 'seemly' +import { pxfy, repeat } from 'seemly' import { computed, defineComponent, @@ -95,7 +95,7 @@ export default defineComponent({ } }, render () { - const { repeat, style, mergedClsPrefix, $attrs } = this + const { repeat: repeatProp, style, mergedClsPrefix, $attrs } = this // BUG: // Chrome devtools can't read the element // Maybe it's a bug of chrome @@ -109,15 +109,8 @@ export default defineComponent({ $attrs ) ) - if (repeat > 1) { - return ( - <> - {Array.apply(null, { length: repeat } as any).map((_) => [ - child, - '\n' - ])} - - ) + if (repeatProp > 1) { + return <>{repeat(repeatProp, null).map((_) => [child, '\n'])} } return child } diff --git a/src/slider/src/Slider.tsx b/src/slider/src/Slider.tsx index 827aafc69..ec43f895f 100644 --- a/src/slider/src/Slider.tsx +++ b/src/slider/src/Slider.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/space-before-function-paren */ import { h, ref, @@ -106,7 +107,7 @@ export type SliderProps = ExtractPublicPropTypes export default defineComponent({ name: 'Slider', props: sliderProps, - setup (props) { + setup(props) { const { mergedClsPrefixRef, namespaceRef, inlineThemeDisabled } = useConfig(props) const themeRef = useTheme( @@ -234,7 +235,7 @@ export default defineComponent({ return mergedMarks }) - function getHandleStyle (value: number, index: number): Record { + function getHandleStyle(value: number, index: number): Record { const percentage = valueToPercentage(value) const { value: styleDirection } = styleDirectionRef return { @@ -242,31 +243,31 @@ export default defineComponent({ zIndex: index === activeIndexRef.value ? 1 : 0 } } - function isShowTooltip (index: number): boolean { + function isShowTooltip(index: number): boolean { return ( props.showTooltip || hoverIndexRef.value === index || (activeIndexRef.value === index && draggingRef.value) ) } - function shouldKeepTooltipTransition (index: number): boolean { + function shouldKeepTooltipTransition(index: number): boolean { if (!draggingRef.value) return true return !( activeIndexRef.value === index && previousIndexRef.value === index ) } - function focusActiveHandle (index: number): void { + function focusActiveHandle(index: number): void { if (~index) { activeIndexRef.value = index - handleRefs.value.get(index)?.focus() + handleRefs.get(index)?.focus() } } - function syncPosition (): void { - followerRefs.value.forEach((inst, index) => { + function syncPosition(): void { + followerRefs.forEach((inst, index) => { if (isShowTooltip(index)) inst.syncPosition() }) } - function doUpdateValue (value: number | number[]): void { + function doUpdateValue(value: number | number[]): void { const { 'onUpdate:value': _onUpdateValue, onUpdateValue } = props const { nTriggerFormInput, nTriggerFormChange } = formItem if (onUpdateValue) call(onUpdateValue as OnUpdateValueImpl, value) @@ -275,7 +276,7 @@ export default defineComponent({ nTriggerFormInput() nTriggerFormChange() } - function dispatchValueUpdate (value: number | number[]): void { + function dispatchValueUpdate(value: number | number[]): void { const { range } = props if (range) { if (Array.isArray(value)) { @@ -291,7 +292,7 @@ export default defineComponent({ } } } - function doDispatchValue (value: number, index: number): void { + function doDispatchValue(value: number, index: number): void { if (props.range) { const values = arrifiedValueRef.value.slice() values.splice(index, 1, value) @@ -302,7 +303,7 @@ export default defineComponent({ } // value conversion - function sanitizeValue ( + function sanitizeValue( value: number, currentValue: number, stepBuffer?: number @@ -346,24 +347,24 @@ export default defineComponent({ } return closestMark ? clampValue(closestMark.value) : currentValue } - function clampValue (value: number): number { + function clampValue(value: number): number { return Math.min(props.max, Math.max(props.min, value)) } - function valueToPercentage (value: number): number { + function valueToPercentage(value: number): number { const { max, min } = props return ((value - min) / (max - min)) * 100 } - function percentageToValue (percentage: number): number { + function percentageToValue(percentage: number): number { const { max, min } = props return min + (max - min) * percentage } - function getRoundValue (value: number): number { + function getRoundValue(value: number): number { const { step, min } = props if (Number(step) <= 0 || step === 'mark') return value const newValue = Math.round((value - min) / step) * step + min return Number(newValue.toFixed(precisionRef.value)) } - function getClosestMark ( + function getClosestMark( currentValue: number, markValues = markValuesRef.value, buffer?: number @@ -388,7 +389,7 @@ export default defineComponent({ } return closestMark } - function getPointValue (event: MouseEvent | TouchEvent): number | undefined { + function getPointValue(event: MouseEvent | TouchEvent): number | undefined { const railEl = handleRailRef.value if (!railEl) return const touchEvent = isTouchEvent(event) ? event.touches[0] : event @@ -406,7 +407,7 @@ export default defineComponent({ } // dom event handle - function handleRailKeyDown (e: KeyboardEvent): void { + function handleRailKeyDown(e: KeyboardEvent): void { if (mergedDisabledRef.value || !props.keyboard) return const { vertical, reverse } = props switch (e.key) { @@ -428,7 +429,7 @@ export default defineComponent({ break } } - function handleStepValue (ratio: number): void { + function handleStepValue(ratio: number): void { const activeIndex = activeIndexRef.value if (activeIndex === -1) return const { step } = props @@ -443,7 +444,7 @@ export default defineComponent({ activeIndex ) } - function handleRailMouseDown (event: MouseEvent | TouchEvent): void { + function handleRailMouseDown(event: MouseEvent | TouchEvent): void { if (mergedDisabledRef.value) return if (!isTouchEvent(event) && event.button !== eventButtonLeft) { return @@ -465,7 +466,7 @@ export default defineComponent({ ) } } - function startDragging (): void { + function startDragging(): void { if (!draggingRef.value) { draggingRef.value = true if (props.onDragstart) call(props.onDragstart) @@ -475,7 +476,7 @@ export default defineComponent({ on('mousemove', document, handleMouseMove) } } - function stopDragging (): void { + function stopDragging(): void { if (draggingRef.value) { draggingRef.value = false if (props.onDragend) call(props.onDragend) @@ -485,29 +486,30 @@ export default defineComponent({ off('mousemove', document, handleMouseMove) } } - function handleMouseMove (event: MouseEvent | TouchEvent): void { + function handleMouseMove(event: MouseEvent | TouchEvent): void { const { value: activeIndex } = activeIndexRef if (!draggingRef.value || activeIndex === -1) { stopDragging() return } - const pointValue = getPointValue(event) as number + const pointValue = getPointValue(event) + if (pointValue === undefined) return doDispatchValue( sanitizeValue(pointValue, arrifiedValueRef.value[activeIndex]), activeIndex ) } - function handleMouseUp (): void { + function handleMouseUp(): void { stopDragging() } - function handleHandleFocus (index: number): void { + function handleHandleFocus(index: number): void { activeIndexRef.value = index // Wake focus style if (!mergedDisabledRef.value) { hoverIndexRef.value = index } } - function handleHandleBlur (index: number): void { + function handleHandleBlur(index: number): void { if (activeIndexRef.value === index) { activeIndexRef.value = -1 stopDragging() @@ -516,10 +518,10 @@ export default defineComponent({ hoverIndexRef.value = -1 } } - function handleHandleMouseEnter (index: number): void { + function handleHandleMouseEnter(index: number): void { hoverIndexRef.value = index } - function handleHandleMouseLeave (index: number): void { + function handleHandleMouseLeave(index: number): void { if (hoverIndexRef.value === index) { hoverIndexRef.value = -1 } @@ -659,7 +661,7 @@ export default defineComponent({ onRender: themeClassHandle?.onRender } }, - render () { + render() { const { mergedClsPrefix, themeClass, formatTooltip } = this this.onRender?.() return ( diff --git a/src/slider/src/utils.ts b/src/slider/src/utils.ts index 28e7f1972..bd82cabfd 100644 --- a/src/slider/src/utils.ts +++ b/src/slider/src/utils.ts @@ -1,9 +1,4 @@ -import { - ref, - onBeforeUpdate, - type Ref, - type ComponentPublicInstance -} from 'vue' +import { onBeforeUpdate, type ComponentPublicInstance } from 'vue' export function isTouchEvent (e: MouseEvent | TouchEvent): e is TouchEvent { return window.TouchEvent && e instanceof window.TouchEvent @@ -13,16 +8,16 @@ type RefType = HTMLElement | ComponentPublicInstance type RefKey = number type RefsValue = Map export function useRefs (): [ - Ref>, + RefsValue, (key: RefKey) => (el: any) => void ] { - const refs = ref>(new Map()) + const refs = new Map() const setRefs = (index: RefKey) => (el: any) => { - refs.value.set(index, el) + refs.set(index, el) } onBeforeUpdate(() => { - refs.value.clear() + refs.clear() }) return [refs, setRefs] diff --git a/src/tabs/src/Tab.tsx b/src/tabs/src/Tab.tsx index 4887d5a07..6252f3c27 100644 --- a/src/tabs/src/Tab.tsx +++ b/src/tabs/src/Tab.tsx @@ -114,6 +114,7 @@ export default defineComponent({ onMouseenter: trigger === 'hover' ? this.activateTab : undefined, style: internalAddable ? undefined : style }, + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument this.internalCreatedByPane ? ((this.tabProps || {}) as any) : this.$attrs diff --git a/src/tabs/src/Tabs.tsx b/src/tabs/src/Tabs.tsx index a03c9bc01..f694ad8e9 100644 --- a/src/tabs/src/Tabs.tsx +++ b/src/tabs/src/Tabs.tsx @@ -16,7 +16,8 @@ import { watchEffect, type ExtractPropTypes, cloneVNode, - TransitionGroup + TransitionGroup, + type VNodeChild } from 'vue' import { VResizeObserver, VXScroll, type VXScrollInst } from 'vueuc' import { throttle } from 'lodash-es' @@ -163,9 +164,8 @@ export default defineComponent({ compitableValueRef.value ?? props.defaultValue ?? (slots.default - ? ((flatten((slots as any).default())[0] as any)?.props?.name as - | string - | number) + ? ((flatten((slots as any).default() as VNodeChild[])[0] as any) + ?.props?.name as string | number) : null) ) const mergedValueRef = useMergedState( @@ -408,7 +408,9 @@ export default defineComponent({ } } if (type !== 'segment') { - deriveScrollShadow(xScrollInstRef.value?.$el) + deriveScrollShadow( + (xScrollInstRef.value?.$el as undefined | HTMLElement) || null + ) } } const handleNavResize = throttle(_handleNavResize, 64) @@ -440,7 +442,9 @@ export default defineComponent({ addTabFixedRef.value = false } } - deriveScrollShadow(xScrollInstRef.value?.$el) + deriveScrollShadow( + (xScrollInstRef.value?.$el as undefined | HTMLElement) || null + ) } const handleTabsResize = throttle(_handleTabsResize, 64) @@ -701,7 +705,9 @@ export default defineComponent({ )} {showPane ? tabPaneChildren.map((tabPaneVNode: any, index: number) => { - renderNameListRef.value.push(tabPaneVNode.props.name) + renderNameListRef.value.push( + tabPaneVNode.props.name as string | number + ) return justifyTabDynamicProps( { - renderNameListRef.value.push(tabVNode.props.name) + renderNameListRef.value.push( + tabVNode.props.name as string | number + ) if (index !== 0 && !mergedJustifyContent) { return justifyTabDynamicProps( - createLeftPaddedTabVNode(tabVNode) + createLeftPaddedTabVNode(tabVNode as VNode) ) } else { - return justifyTabDynamicProps(tabVNode) + return justifyTabDynamicProps(tabVNode as VNode) } })} {!addTabFixed && addable && isCard @@ -804,7 +812,9 @@ export default defineComponent({
{showPane ? tabPaneChildren.map((tabPaneVNode: any, index: number) => { - renderNameListRef.value.push(tabPaneVNode.props.name) + renderNameListRef.value.push( + tabPaneVNode.props.name as string | number + ) return ( { - renderNameListRef.value.push(tabVNode.props.name) + renderNameListRef.value.push( + tabVNode.props.name as string | number + ) if (index === 0) { return tabVNode } else { - return createLeftPaddedTabVNode(tabVNode) + return createLeftPaddedTabVNode(tabVNode as VNode) } })}
diff --git a/src/theme-editor/src/ThemeEditor.tsx b/src/theme-editor/src/ThemeEditor.tsx index 26772efba..ea4a0225f 100644 --- a/src/theme-editor/src/ThemeEditor.tsx +++ b/src/theme-editor/src/ThemeEditor.tsx @@ -105,10 +105,10 @@ export default defineComponent({ }) const showPanelRef = ref(false) const overridesRef = ref( - JSON.parse(localStorage['naive-ui-theme-overrides'] || '{}') + JSON.parse((localStorage['naive-ui-theme-overrides'] as string) || '{}') ) const tempOverridesRef = ref( - JSON.parse(localStorage['naive-ui-theme-overrides'] || '{}') + JSON.parse((localStorage['naive-ui-theme-overrides'] as string) || '{}') ) const varNamePatternRef = ref('') const compNamePatternRef = ref('') diff --git a/src/time-picker/tests/TimePicker.spec.ts b/src/time-picker/tests/TimePicker.spec.ts index 16a2fc642..2b8b68ce0 100644 --- a/src/time-picker/tests/TimePicker.spec.ts +++ b/src/time-picker/tests/TimePicker.spec.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/non-nullable-type-assertion-style */ import { mount } from '@vue/test-utils' import { h } from 'vue' import { NTimePicker } from '../index' diff --git a/src/tree/src/utils.ts b/src/tree/src/utils.ts index 10be679f7..6896d7bc1 100644 --- a/src/tree/src/utils.ts +++ b/src/tree/src/utils.ts @@ -24,7 +24,7 @@ function traverse ( nodes?.forEach((node) => { callback(node) traverse( - (node as any)[childrenField], + (node as any)[childrenField] as TreeOption[] | undefined, childrenField, callback, callbackAfter @@ -52,10 +52,10 @@ export function keysWithFilter ( (node) => { path.push(node) if (filter(pattern, node)) { - highlightKeySet.add((node as any)[keyField]) + highlightKeySet.add((node as any)[keyField] as Key) for (let i = path.length - 2; i >= 0; --i) { - if (!keys.has((path[i] as any)[keyField])) { - keys.add((path[i] as any)[keyField]) + if (!keys.has((path[i] as any)[keyField] as Key)) { + keys.add((path[i] as any)[keyField] as Key) } else { return } diff --git a/src/upload/src/Upload.tsx b/src/upload/src/Upload.tsx index 3cf6c80c3..84ba5a077 100644 --- a/src/upload/src/Upload.tsx +++ b/src/upload/src/Upload.tsx @@ -270,7 +270,9 @@ function submitImpl ( request.withCredentials = withCredentials const formData = new FormData() appendData(formData, data, file) - formData.append(fieldName, file.file as File) + if (file.file !== null) { + formData.append(fieldName, file.file) + } registerHandler(inst, file, request) if (action !== undefined) { request.open(method.toUpperCase(), action) @@ -506,6 +508,7 @@ export default defineComponent({ let nextTickChain = Promise.resolve() fileInfos.forEach((fileInfo) => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument nextTickChain = nextTickChain.then(nextTick as any).then(() => { fileInfo && doChange(fileInfo, e, {