Код ошибки:
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)
}