import { computed, getCurrentInstance } from "vue" export function useModel( propName = "modelValue", options: { type?: "object" | "array" } = {} ) { const vm = getCurrentInstance()?.proxy if (!vm) throw "useModel is called without an instance" let valueToSet: (arg0: Type) => Type // @ts-expect-error strange typing if (options.type === "object") valueToSet = (value: object) => ({ ...value }) else if (options.type === "array") // @ts-expect-error strange typing valueToSet = (value: unknown[]) => [...value] else valueToSet = (value: Type) => value return computed({ get() { // @ts-expect-error strange typing return vm.$props[propName] }, set(value) { vm.$emit(`update:${propName}`, valueToSet(value)) }, }) }