fix(hooks): type error (#7941)

This commit is contained in:
三咲智子 2022-05-30 09:26:14 +08:00 committed by GitHub
parent 652333e395
commit 37e2bfaee4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 15 additions and 12 deletions

View File

@ -54,11 +54,6 @@
"packages/components/virtual-list/",
"packages/components/visual-hidden/",
"packages/directives/",
"packages/hooks/use-floating/",
"packages/hooks/use-forward-ref/",
"packages/hooks/use-global-config/",
"packages/hooks/use-prop/",
"packages/make-installer.ts",
"packages/utils/dom/",
"packages/utils/vue/"
]

View File

@ -5,6 +5,12 @@ import type { ConfigProviderContext } from '@element-plus/tokens'
const INSTALLED_KEY = Symbol('INSTALLED_KEY')
declare module 'vue' {
interface App {
[INSTALLED_KEY]?: boolean
}
}
export const makeInstaller = (components: Plugin[] = []) => {
const install = (app: App, options?: ConfigProviderContext) => {
if (app[INSTALLED_KEY]) return

View File

@ -2,8 +2,7 @@ import { isRef, onMounted, ref, unref, watchEffect } from 'vue'
import { isClient, unrefElement } from '@vueuse/core'
import { isNil } from 'lodash-unified'
import { arrow as arrowCore, computePosition } from '@floating-ui/dom'
import { buildProps } from '@element-plus/utils'
import { buildProps, keysOf } from '@element-plus/utils'
import type { Ref, ToRefs } from 'vue'
import type {
@ -75,7 +74,7 @@ export const useFloating = ({
middleware: unref(middleware),
})
Object.keys(states).forEach((key) => {
keysOf(states).forEach((key) => {
states[key].value = data[key]
})
}

View File

@ -1,6 +1,6 @@
import { provide } from 'vue'
import type { InjectionKey, Ref } from 'vue'
import type { InjectionKey, ObjectDirective, Ref } from 'vue'
type ForwardRefSetter = <T>(el: T) => void
@ -21,7 +21,9 @@ export const useForwardRef = <T>(forwardRef: Ref<T | null>) => {
})
}
export const useForwardRefDirective = (setForwardRef: ForwardRefSetter) => {
export const useForwardRefDirective = (
setForwardRef: ForwardRefSetter
): ObjectDirective => {
return {
mounted(el) {
setForwardRef(el)

View File

@ -1,6 +1,7 @@
import { computed, getCurrentInstance, inject, provide, ref, unref } from 'vue'
import { configProviderContextKey } from '@element-plus/tokens'
import { debugWarn, keysOf } from '@element-plus/utils'
import type { MaybeRef } from '@vueuse/core'
import type { App, Ref } from 'vue'
import type { ConfigProviderContext } from '@element-plus/tokens'
@ -66,7 +67,7 @@ const mergeConfig = (
b: ConfigProviderContext
): ConfigProviderContext => {
const keys = [...new Set([...keysOf(a), ...keysOf(b)])]
const obj = {}
const obj: Record<string, any> = {}
for (const key of keys) {
obj[key] = b[key] ?? a[key]
}

View File

@ -3,5 +3,5 @@ import type { ComputedRef } from 'vue'
export const useProp = <T>(name: string): ComputedRef<T | undefined> => {
const vm = getCurrentInstance()!
return computed(() => vm.proxy?.$props[name] ?? undefined)
return computed(() => (vm.proxy?.$props as any)[name] ?? undefined)
}