fix [api]: typing in modelWrapper

This commit is contained in:
Alice 2023-01-29 00:07:25 +01:00
parent 7c33864ae3
commit 05affca69d

View file

@ -4,19 +4,21 @@ export function useModel<Type>(
propName = "modelValue",
options: { type?: "object" | "array" } = {}
) {
const vm = getCurrentInstance().proxy
const vm = getCurrentInstance()?.proxy
if (!vm) throw "useModel is called without an instance"
let valueToSet
if (options.type === "object") {
valueToSet = (value: object) => {
return { ...value }
}
} else if (options.type === "array") {
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) => value
else valueToSet = (value: Type) => value
return computed<Type>({
get() {
// @ts-expect-error strange typing
return vm.$props[propName]
},
set(value) {