I have created a hook function and want to reuse it in other places:
import { ref, Ref, reactive } from 'vue'
const useSelectAarray = <T>(items: T[]) => {
const selectItem: Ref<T|null> = ref(null)
const options = reactive([...items])
const select = (key: string, value: any) => {
const trigger = options.find((item: { [index: string]: any }) => item[key] === value)
if (typeof trigger !== 'undefined') {
selectItem.value = trigger
}
}
return {
selectItem,
select,
items: options
}
}
But at selectItem.value = trigger, I get an type error Type 'UnwrapRefSimple<T>' is not assignable to type 'T'。
How can I solve this problem?