fix: eslint

This commit is contained in:
zhanglecong 2023-12-18 10:00:48 +08:00
parent 4b4d58e6b5
commit 21ee7f99f2
56 changed files with 266 additions and 214 deletions

View File

@ -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",

View File

@ -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

View File

@ -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)
}
}

View File

@ -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' },
{

View File

@ -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,

View File

@ -739,8 +739,8 @@ export default defineComponent({
}}
</VOverflow>
)
) : maxTagCountNumeric ? (
createOriginalTagNodes().concat(counter as JSX.Element)
) : maxTagCountNumeric && counter ? (
createOriginalTagNodes().concat(counter)
) : (
createOriginalTagNodes()
)
@ -889,11 +889,11 @@ export default defineComponent({
<div class={`${clsPrefix}-base-selection-input__content`}>
{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)}
</div>
</div>

View File

@ -15,9 +15,12 @@ import {
export function useInjectionInstanceCollection (
injectionName: string | InjectionKey<unknown>,
collectionKey: string,
registerKeyRef: Ref<any>
registerKeyRef: Ref<string | undefined>
): void {
const injection = inject<any | null>(injectionName, null)
const injection = inject<Record<string, Record<string, any>> | 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)

View File

@ -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
}

View File

@ -203,6 +203,7 @@ export default defineComponent({
role: 'alert'
}
return this.visible ? (
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
<div {...mergeProps(this.$attrs, attrs as any)}>
{this.closable && (
<NBaseClose

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-argument */
import {
h,
defineComponent,
@ -60,7 +61,7 @@ const transitionProperties = [
] as const
type TransitionStyle = Partial<
Pick<CSSProperties, typeof transitionProperties[number]>
Pick<CSSProperties, (typeof transitionProperties)[number]>
>
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)
}

View File

@ -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
)
}
}

View File

@ -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)

View File

@ -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
}

View File

@ -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
}

View File

@ -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<any> | DefineComponent<any>
)
}
}
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)

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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
}

View File

@ -310,7 +310,7 @@ describe('n-data-table', () => {
}
],
filter (value: any, row) {
return row.address.includes(value)
return row.address.includes(value as string)
}
}
]

View File

@ -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 {

View File

@ -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 = {

View File

@ -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 {

View File

@ -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'

View File

@ -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'

View File

@ -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 = (
<div class={`${clsPrefix}-dropdown-option`} {...nodeProps?.(rawNode)}>
<div
class={`${clsPrefix}-dropdown-option`}
{...nodeProps?.(rawNode as DropdownMixedOption)}
>
<div
class={`${clsPrefix}-dropdown-option-body ${clsPrefix}-dropdown-option-body--group`}
>
@ -63,7 +67,7 @@ export default defineComponent({
data-dropdown-option
>
{renderLabel
? renderLabel(rawNode)
? renderLabel(rawNode as DropdownMixedOption)
: render(rawNode.title ?? rawNode[this.labelField])}
</div>
<div

View File

@ -14,6 +14,11 @@ import {
} from 'vue'
import { VBinder, VTarget, VFollower, type FollowerPlacement } from 'vueuc'
import { useMemo } from 'vooks'
import { happensIn } from 'seemly'
import type {
MenuGroupOption,
MenuOptionSharedPart
} from '../../menu/src/interface'
import { ChevronRightIcon } from '../../_internal/icons'
import { render, useDeferredTrue } from '../../_utils'
import { NIcon } from '../../icon'
@ -32,7 +37,6 @@ import type {
DropdownIgnoredOption,
DropdownOption
} from './interface'
import { happensIn } from 'seemly'
export interface NDropdownOptionInjection {
enteringSubmenuRef: Ref<boolean>
@ -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<MenuOptionSharedPart | MenuGroupOption>
)
submenuVNode = (
<NDropdownMenu
@ -272,42 +275,49 @@ export default defineComponent({
data-dropdown-option
{...optionNodeProps}
>
{h('div', mergeProps(builtinProps as any, props as any), [
<div
class={[
`${clsPrefix}-dropdown-option-body__prefix`,
siblingHasIcon &&
`${clsPrefix}-dropdown-option-body__prefix--show-icon`
]}
>
{[renderIcon ? renderIcon(rawNode) : render(rawNode.icon)]}
</div>,
<div
data-dropdown-option
class={`${clsPrefix}-dropdown-option-body__label`}
>
{/* TODO: Workaround, menu compatible */}
{renderLabel
? renderLabel(rawNode)
: render(rawNode[this.labelField] ?? rawNode.title)}
</div>,
<div
data-dropdown-option
class={[
`${clsPrefix}-dropdown-option-body__suffix`,
siblingHasSubmenu &&
`${clsPrefix}-dropdown-option-body__suffix--has-submenu`
]}
>
{this.hasSubmenu ? (
<NIcon>
{{
default: () => <ChevronRightIcon />
}}
</NIcon>
) : null}
</div>
])}
{h(
'div',
mergeProps(
builtinProps as Record<string, any>,
props as Record<string, any>
),
[
<div
class={[
`${clsPrefix}-dropdown-option-body__prefix`,
siblingHasIcon &&
`${clsPrefix}-dropdown-option-body__prefix--show-icon`
]}
>
{[renderIcon ? renderIcon(rawNode) : render(rawNode.icon)]}
</div>,
<div
data-dropdown-option
class={`${clsPrefix}-dropdown-option-body__label`}
>
{/* TODO: Workaround, menu compatible */}
{renderLabel
? renderLabel(rawNode)
: render(rawNode[this.labelField] ?? rawNode.title)}
</div>,
<div
data-dropdown-option
class={[
`${clsPrefix}-dropdown-option-body__suffix`,
siblingHasSubmenu &&
`${clsPrefix}-dropdown-option-body__suffix--has-submenu`
]}
>
{this.hasSubmenu ? (
<NIcon>
{{
default: () => <ChevronRightIcon />
}}
</NIcon>
) : null}
</div>
]
)}
{this.hasSubmenu ? (
<VBinder>
{{

View File

@ -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

View File

@ -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)

View File

@ -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
)

View File

@ -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

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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})`

View File

@ -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})`

View File

@ -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(

View File

@ -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

View File

@ -162,13 +162,14 @@ export function getRelativePosition (
if (isInput && prop === 'lineHeight') {
// Special case for <input>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) {

View File

@ -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

View File

@ -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 {

View File

@ -132,6 +132,7 @@ export default defineComponent({
mergedClsPrefixRef
)
const followerRef = ref<FollowerInst | null>(null)
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
const NPopover = inject<PopoverInjection>('NPopover') as PopoverInjection
const bodyRef = ref<HTMLElement | null>(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
)

View File

@ -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<HTMLElement | null>,
style: Ref<CSSProperties>,
style: ComputedRef<CSSProperties[]>,
onMouseenter: (e: MouseEvent) => void,
onMouseleave: (e: MouseEvent) => void
) => VNode

View File

@ -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'

View File

@ -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
])}
>
{{

View File

@ -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(

View File

@ -36,9 +36,11 @@ const Scrollbar = defineComponent({
const scrollbarInstRef = ref<InternalScrollbarInst | null>(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])
}
}

View File

@ -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

View File

@ -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
}

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/space-before-function-paren */
import {
h,
ref,
@ -106,7 +107,7 @@ export type SliderProps = ExtractPublicPropTypes<typeof sliderProps>
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<string, any> {
function getHandleStyle(value: number, index: number): Record<string, any> {
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 (

View File

@ -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<T extends RefType> = Map<RefKey, T>
export function useRefs<T extends RefType> (): [
Ref<RefsValue<T>>,
RefsValue<T>,
(key: RefKey) => (el: any) => void
] {
const refs = ref<RefsValue<T>>(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]

View File

@ -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

View File

@ -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(
<Tab
{...tabPaneVNode.props}
@ -723,13 +729,15 @@ export default defineComponent({
)
})
: tabChildren.map((tabVNode: any, index: number) => {
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({
<div class={`${mergedClsPrefix}-tabs-rail`} ref="tabsRailElRef">
{showPane
? tabPaneChildren.map((tabPaneVNode: any, index: number) => {
renderNameListRef.value.push(tabPaneVNode.props.name)
renderNameListRef.value.push(
tabPaneVNode.props.name as string | number
)
return (
<Tab
{...tabPaneVNode.props}
@ -820,11 +830,13 @@ export default defineComponent({
)
})
: tabChildren.map((tabVNode: any, index: number) => {
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)
}
})}
</div>

View File

@ -105,10 +105,10 @@ export default defineComponent({
})
const showPanelRef = ref(false)
const overridesRef = ref<any>(
JSON.parse(localStorage['naive-ui-theme-overrides'] || '{}')
JSON.parse((localStorage['naive-ui-theme-overrides'] as string) || '{}')
)
const tempOverridesRef = ref<any>(
JSON.parse(localStorage['naive-ui-theme-overrides'] || '{}')
JSON.parse((localStorage['naive-ui-theme-overrides'] as string) || '{}')
)
const varNamePatternRef = ref('')
const compNamePatternRef = ref('')

View File

@ -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'

View File

@ -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
}

View File

@ -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, {