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