Answer the question
In order to leave comments, you need to log in
How to correctly import typescript(2698) vue 3 function?
Error code:
TS2698: Spread types may only be created from object types.
33 | return {
34 | contact,
> 35 | ...useHandleClick(handleClick)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36 | }
37 | }
import { onMounted, onBeforeUnmount } from 'vue'
interface IFunction {
(e: Event): void
}
export function useHandleClick (fn: IFunction): void {
onMounted(() => {
document.addEventListener('click', fn)
})
onBeforeUnmount(() => {
document.removeEventListener('click', fn)
})
}
const handleClick = (event: Event): void => {
const target = event.target as Element
if (target.closest('button') || target.closest('.contact')) return
emit('close')
}
// noinspection JSVoidFunctionReturnValueUsed
return {
...useHandleClick(handleClick)
}
Answer the question
In order to leave comments, you need to log in
https://developer.mozilla.org/en/docs/Web/JavaScript...
Spread types may only be created from object types.
undefined
. useSomething
) hook is done like this - an object is returned, whose fields are assigned to another object using the spread operator. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question