type EventT<T> = {
  // @ts-ignore
  [key in `update:${keyof T}`]: 1
}
export default function <T extends { [key: string]: any }>(props: T, propName: keyof T, emits: (event: keyof EventT<T>, ...args: any[]) => void) {
  return computed({
    get() {
      return new Proxy(props[propName], {
        get(target, key) {
          return Reflect.get(target, key)
        },
        set(target, key, value) {
          Reflect.set(target, key, value)
          emits(('update:' + (propName as string)) as keyof EventT<T>, {
            ...target,
            [key]: value,
          })
          return true
        },
      })
    },
    set(val) {
      emits(('update:' + (propName as string)) as keyof EventT<T>, val)
    },
  })
}
