fix(hooks): add type remove ts error (#4055)

This commit is contained in:
btea
2021-10-27 15:44:27 -05:00
committed by GitHub
parent 883fd8d6ef
commit cb03f4d890
5 changed files with 9 additions and 9 deletions

View File

@@ -39,7 +39,7 @@ function translate(path, option, current) {
}
export const useLocale = () => {
const vm = getCurrentInstance()
const vm = getCurrentInstance()!
const props = vm.props as {
locale: Language
}
@@ -60,7 +60,7 @@ export const useLocale = () => {
locale,
lang,
t,
}
} as LocaleContext
// this could be broken if someone tries to do following:

View File

@@ -4,7 +4,7 @@ import { kebabCase } from '@element-plus/utils/util'
const useMigrating = function () {
onMounted(() => {
const instance = getCurrentInstance()
const instance = getCurrentInstance()!
if (process.env.NODE_ENV === 'production') return
if (!instance.vnode) return
const { props = {} } = getMigratingConfig()
@@ -16,7 +16,7 @@ const useMigrating = function () {
if (props[propName]) {
debugWarn(
'Element Migrating',
`[${instance.proxy.$options.name}][Attribute]: ${props[propName]}`
`[${instance.proxy?.$options.name}][Attribute]: ${props[propName]}`
)
}
}

View File

@@ -32,7 +32,7 @@ export const useModelToggle = ({
onShow,
onHide,
}: ModelToggleParams) => {
const { appContext, props, proxy, emit } = getCurrentInstance()
const { appContext, props, proxy, emit } = getCurrentInstance()!
const hasUpdateHandler = computed(() =>
isFunction(props['onUpdate:modelValue'])
@@ -120,7 +120,7 @@ export const useModelToggle = ({
}
}
watch(() => props.modelValue, onChange)
watch(() => props.modelValue, onChange as any)
if (
shouldHideWhenRouteChanges &&

View File

@@ -21,7 +21,7 @@ export const useTargetEvents = (
onHide: Handler,
onToggle: Handler
) => {
const { props } = getCurrentInstance()
const { props } = getCurrentInstance()!
let triggerFocused = false
@@ -67,7 +67,7 @@ export const useTargetEvents = (
const mapEvents = (t: TriggerType) => {
const events = {} as PopperEvents
triggerEventsMap[t].forEach((event) => {
triggerEventsMap[t]?.forEach((event) => {
events[event] = popperEventsHandler
})

View File

@@ -20,7 +20,7 @@ export default (contentRenderer: () => VNode, appendToBody: Ref<boolean>) => {
}
}
let $el: HTMLElement = null
let $el: HTMLElement | null = null
const showTeleport = () => {
isTeleportVisible.value = true